/* * compute average of integers entered as input (any number of them) * (this is the sum-loop program slightly modified) */ #include double average(void) { long n; long sum = 0; int count = 0; while (scanf("%ld", &n) == 1) { sum += n; ++count; } return ((double) sum)/ count; } int main(void) { printf("enter integers to average, anything else to stop\n"); printf("average %lf\n", average()); return 0; }