Kodewick
Start learning →
Mini challenge←→0 / 70

Above average

#034Mini challengeArraysConditions7 min

A skipping contest: the counts of n people are in scores (at least 1). The average avg is already worked out. Write the rest of above_average(scores, n): go through the array again and count the people above the average (equal does not count).

Examples
above_average({60, 80, 100}, 3)→1
above_average({70, 70}, 2)→0
The functionint above_average(int scores[], int n)
main.c
int above_average(int scores[], int n) {
    int sum = 0;
    for (int i = 0; i < n; i++) {
        sum += scores[i];
    }
    double avg = (double)sum / n;
    int count = 0;
    // your code here: another loop: if above avg, add 1 to count
    return count;
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.