← Back to STL Containers
Question 538
Count Even Values
Count Even Values
Write a function int countEven(const array<int, 8>& a) that returns how many of the eight elements are even. Zero and negative even numbers count as even.
The test prints the returned count on its own line. For {1, 2, 3, 4, 5, 6, 7, 8} it prints the output shown in Expected Output.
Do NOT write a main function.Expected Output:
4 2
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
STL Containersstd::array
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.