/* * Program to compute average of integers entered as input (any number of them). */ #include int main(void) { printf("enter integers, anything else to stop\n"); int sum = 0; int count = 0; int input; /* * somewhat cryptic but C-idiomatic: * tries to read a value into input as part of evaluating condition * if it succeeds, loop continues; otherwise it stops */ while (scanf("%d", &input) == 1) { sum += input; count += 1; } printf("average is %f\n", ((double) sum) / count); return 0; }