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
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Check if Array elements can be maximized upto M by adding all elements from another array
- Find elements of an Array which are Odd and Even using STL in C++
- Factorial of Large Number Using boost multiprecision Library
- Generating large Fibonacci numbers using boost library
- Pattern Searching using C++ library
- Replace the odd positioned elements with their cubes and even positioned elements with their squares
- Unordered Sets in C++ Standard Template Library
- Advanced C++ with boost library
- Algorithm Library | C++ Magicians STL Algorithm
- How to add "graphics.h" C/C++ library to gcc compiler in Linux
- The C++ Standard Template Library (STL)
- Pair in C++ Standard Template Library (STL)
- List in C++ Standard Template Library (STL)
- Deque in C++ Standard Template Library (STL)
- Queue in Standard Template Library (STL)
- Priority Queue in C++ Standard Template Library (STL)
- Set in C++ Standard Template Library (STL)
- Multiset in C++ Standard Template Library (STL)
- Map in C++ Standard Template Library (STL)
- Multimap 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 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.