count method in cpp
// my linkedin : https://www.linkedin.com/in/vaalarivan-prasanna-3a07bb203/
vector<int> vec = {1, 2, 1, 1};
cout << count(vec.begin(), vec.end(), 1);
// 3 is printed as 1 occurs thrice in the vector
count method in cpp
// my linkedin : https://www.linkedin.com/in/vaalarivan-prasanna-3a07bb203/
vector<int> vec = {1, 2, 1, 1};
cout << count(vec.begin(), vec.end(), 1);
// 3 is printed as 1 occurs thrice in the vector
count function c++
1 #include <iostream>
2 #include <array>
3 #include <algorithm>
4
5 using namespace std;
6
7 int main(){
8 array<int, 5> 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 */
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us