count_if() function returns the number of elements in a range that satisfy the condition.
Input: 0 1 2 3 4 5 6 7 8 9 Output: Total no of even numbers is: 5 Input: 2 3 4 5 6 7 8 9 10 11 12 13 Output: Total no of even numbers is: 6
count_if(lower_bound, upper_bound, function)
The count_if function takes three parameters, the first two of which are the first and the last position of the sequence of the elements (where the last position is not included in the range) while the third parameter is the function that takes the element of given sequence one by one as a parameter and returns a boolean value on the basis of condition
specified in that function.
Then, count_if() returns the number of elements in the given sequence for which the comparator function
(third parameter) returns true.
Total no of even numbers is: 5
- cin get() in C++ with Examples
- Difference between Increment and Decrement Operators
- How to discretize an Ellipse or Circle to a Polygon using C++ Graphics?
- Map of Vectors in C++ STL with Examples
- Problem in comparing Floating point numbers and how to compare them correctly?
- exit(0) vs exit(1) in C/C++ with Examples
- Julia Fractal set in C/C++ Using Graphics
- Find two Composite Numbers such that there difference is N
- Mandlebrot Set in C/C++ Using Graphics
- C++ program to print all Even and Odd numbers from 1 to N
- Creating Butterfly themed Fractal in C++ Using Graphics
- Reverse the content of a file and store it in another
- How to pass or return a structure to/from a Function in C/C++?
- Minimum cells to be flipped to get a 2*2 submatrix with equal elements
- Nested Loops in C++ with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.