এই টিউটোরিয়ালে, আমরা C++ STL-এ বাইনারি অ্যারেতে ১ এবং ০-এর সংখ্যা গণনা করার একটি প্রোগ্রাম আলোচনা করব।
এখানে আমাদের একটি অ্যারে দেওয়া থাকবে। আমাদের কাজ হলো অ্যারেতে উপস্থিত ০ এবং ১-এর সংখ্যা গণনা করা।
উদাহরণ
#include <bits/stdc++.h> using namespace std; // checking if element is 1 or not bool isOne(int i){ if (i == 1) return true; else return false; } int main(){ int a[] = { 1, 0, 0, 1, 0, 0, 1 }; int n = sizeof(a) / sizeof(a[0]); int count_of_one = count_if(a, a + n, isOne); cout << "1's: " << count_of_one << endl; cout << "0's: " << (n - count_of_one) << endl; return 0; }আউটপুট
1's: 3 0's: 4