/* * Program to compute sum of integers entered as input,using recursion. * * Input is any number of integers, ending with anything but an integer. */ #include int sum(void); int main(void) { printf("enter integers, anything else to stop\n"); printf("sum is %d\n", sum()); return 0; } /* * compute and return sum of integers from stdin, stopping when anything else * is entered */ int sum(void) { int input; if (scanf("%d", &input) != 1) { /* non-integer input -- the end */ return 0; } else { /* add this input to sum of remaining inputs */ return input + sum(); } }