← Back to STL Containers
Question 536
Five Numbers from Input
Five Numbers from Input
Write a program that reads exactly five integers from standard input (separated by spaces or newlines) into anarray<int, 5>, then prints their sum and their average. Print two lines: the wordSum:, a space and the sum as an integer, then the wordAverage:, a space and the average (sum divided by 5.0) with exactly one decimal place usingfixedandsetprecision(1)from<iomanip>. Example input: 1 2 3 4 5 The output for that input is shown in Expected Output.
Expected Output:
Sum: 15 Average: 3.0 Sum: 23 Average: 4.6
= 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.