Kodewick
Start learning →
Basic←→0 / 70

Average rain

#030BasicArraysOutput4 min

The rain (in mm) for the 5 school days is in rain, and sum is already added up. Show Average: 6.2 mm, the average with %.1f. Careful: in sum / 5 both sides are whole numbers, so the result is 6 and the decimals are gone.

Should show
Average: 6.2 mm
main.c
#include <stdio.h>

int main(void) {
    int rain[5] = {12, 0, 7, 3, 9};
    int sum = 0;
    for (int i = 0; i < 5; i++) {
        sum += rain[i];
    }
    // your code here: printf the average rain (one decimal place)
    return 0;
}
Ctrl + Enter runs too
Result

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