
The crux of this problem's solution lies in discarding the invalid grades and keeping count of the number of valid grades, since this number is not necessarily the same as the number of lines of input. The program below reads the grades and sums those that are valid. Finally, it properly computes the mean.
#include <stdio.h>
main () {
FILE *fin = fopen ("stat3.in", "r");
FILE *fout = fopen ("stat3.out", "w");
int n, realn, i, sum, number;
sum = realn = 0;
fscanf (fin, "%d", &n);
for (i = 0; i < n; i++) {
fscanf (fin, "%d", &number);
if (number <= 0) continue;
sum += number;
realn++;
}
fprintf (fout, "%d\n", (int)(0.5+10.0*(sum/(double)realn)));
exit (0);
}