/* * Program demonstrating use of recursion to "count" * (print numbers from start to limit). * * Input: two integers n, m * * Output: all integers starting with n and ending with m. */ #include /* Count (print) numbers from start through limit */ void count_up(int start, int limit) { if (start > limit) { return; } else { printf("%d\n", start); count_up(start + 1, limit); return; } } /* Main program */ int main(void) { int start; int limit; printf("enter start, limit\n"); if (scanf("%d %d", &start, &limit) != 2) { printf("error: input not numeric\n"); } else { if (start > limit) { printf("start %d is greater than limit %d\n", start, limit); } printf("\ncounting with recursion:\n"); count_up(start, limit); } return 0; }