We are given an array of elements and we have to check the whether each element is even or not.
Input : [2, 4, 6, 8, 9] Output : All the elements are not even Input : [4, 6, 8, 12, 14] Output : Alla the elements are even
Approach: The above problem can be solved using for loop but in C++ we have all_of() algorithm which operates on whole array and save time to write code for loop and checks each element for the specified property.
Note that all_of() also uses loop internally, it just saves our time of writing a loop code.
All are not even elements
- Quickly check if two STL vectors contain same elements or not
- snprintf() in C library
- SDL library in C/C++ with examples
- <iterator> library in C++ STL
- <strings> library in C++ STL
- <algorithms> library in C++ STL
- <regex> library in C++ STL
- <numeric> library in C++ STL
- Get first and last elements from Array and Vector in CPP
- Find elements of an Array which are Odd and Even using STL in C++
- Elements present in first array and not in second using STL in C++
- How to find the sum of elements of an Array using STL in C++?
- Advanced C++ with boost library
- Set in C++ Standard Template Library (STL)
- Map in C++ Standard Template Library (STL)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.