Dynamic Array
Read an integer N, then read N integers. Store them in a dynamically allocated array (using malloc). Print the sum and the average (with 2 decimal places) of the numbers. Don't forget to free the memory.
Input
- First line: an integer
N(1 <= N <= 2·10^4) - The next
Nlines: one integer per line (-10^6 <= x <= 10^6) - The sum, and every partial sum along the way, fits in an
int(-2·10^9 <= sum <= 2·10^9)
Output
Two lines:
- First line: the sum (integer)
- Second line: the average (floating point, 2 decimal places)
Examples
Input:
4
10
20
30
40
Output:
100
25.00
Input:
3
5
5
5
Output:
15
5.00
Input:
1
7
Output:
7
7.00
Input:
3
-5
5
10
Output:
10
3.33
Negative numbers work the same way: the sum can be smaller than any single positive value, and the average still rounds to 2 decimal places.