Sum of N Numbers

Lab C Beginner 10 points

Read n, then n integers. Print their sum and their average with 2 decimals.

Input

n, then n integers.

Output

Two lines.

Example

Input

4
10 20 30 41

Output

101
25.25
Sample input available Sample output available
Editor
C

Hints

Read inside the loop and keep a running total.

Solution explanation

Reading a count first tells you exactly how many numbers follow.

Show solution
#include <stdio.h>

int main() {
    int n, x;
    int sum = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &x);
        sum += x;
    }
    printf("%d\n", sum);
    printf("%.2f\n", (double) sum / n);
    return 0;
}
Output
Answer
HOME LEARN COMMUNITY DASHBOARD