count function c++ code example
Example: count function c++
1 #include
2 #include
3 #include
4
5 using namespace std;
6
7 int main(){
8 array nums = {1, 2, 3, 100, 2};
9 //counting number of twos
10 int numOccurrences = count(nums.begin(), nums.end(), 2);
11 cout << 2 << " appeared " << numOccurrences << " times" << endl;
12 return 0;
13 }
14
15 /*
16 2 appeared 2 times
17 */