Challenge: Above Average

Lab C Intermediate 20 points

Read n and then n marks. Print the average with 2 decimals, then how many marks are above the average.

Input

n (1 ≤ n ≤ 100), then n integers.

Output

Average: X.XX
Above average: K

Example

Input

5
50 60 70 80 90

Output

Average: 70.00
Above average: 2
Sample input available Sample output available
Editor
C

Hints

You need two passes: one to find the average, one to count.

Use (double) total / n for an exact average.

Solution explanation

The average is only known after reading everything, so the marks are stored and checked again in a second loop.

Show solution
#include <stdio.h>

int main() {
    int n;
    int marks[100];
    scanf("%d", &n);
    int total = 0;
    for (int i = 0; i < n; i++) {
        scanf("%d", &marks[i]);
        total += marks[i];
    }
    double avg = (double) total / n;
    int above = 0;
    for (int i = 0; i < n; i++) {
        if (marks[i] > avg) {
            above++;
        }
    }
    printf("Average: %.2f\n", avg);
    printf("Above average: %d\n", above);
    return 0;
}
Output
Answer
HOME LABS COMMUNITY DASHBOARD