#t1143. 数组求和与平均
数组求和与平均
Sum and Average of an Array
Problem Description
Second lesson on arrays: iterate and accumulate at the same time.
After storing integers in an array, one pass over the array gives their sum; the sum divided by gives the average. This pattern keeps coming back in disguise: total score, average height, average temperature... the trick is always the same.
Input Format
The first line contains a positive integer ; the second line contains non-negative integers separated by spaces.
Output Format
One line with two values separated by a space: the sum of the numbers (an integer) and the average (rounded to 2 decimal places).
Sample Input
4
1 2 3 4
Sample Output
10 2.50
Constraints
For 100% of the test data, , and each number does not exceed .
Hint: store the average in a double and print it with printf("%.2f", ...) or cout << fixed << setprecision(2). Note that the largest possible sum, , is , which still fits in an int.