← Back to STL Containers
Question 528
Sum a std::array
Sum a std::array
Write a function int sumArray(const array<int, 5>& a) that returns the sum of all five elements. Use a range-based for loop to visit each element.
The test calls your function and prints the returned value on its own line. For {1, 2, 3, 4, 5} it prints the output shown in Expected Output.
Do NOT write a main function.Expected Output:
15 20
= 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.