/* * compute sum of integers entered as input (any number of them), using * a loop */ #include long sum(void) { long n; long sum = 0; /* arguably a little obscure but very C-idiomatic */ while (scanf("%ld", &n) == 1) { sum += n; } return sum; } int main(void) { printf("enter integers to sum, anything else to stop\n"); printf("sum %ld\n", sum()); return 0; }