/* avg.c: find avg in input data */ #include #include #include int main(int argc, char ** argv) { int N; double x, count; N = 0; scanf("%lf\n", &x); count = x; if ( x < 1 ) { printf("Warning: first value in input = %lf\n", x); printf("You have probably used INCORRECT input data\n"); printf("This program computes the avg for the INPUT data files\n"); printf("Use avg2 to compute the avg for the counting sample !\n"); exit(1); } while ( scanf("%lf\n", &x) > 0 ) { count += x; N++; /* printf("%d count=%d\n", j, count[j]); */ } printf("Avg = %lf\n", count/N); }