/* Computes the Sum of numbers from 1 to N -prints the recursion tree n sum 1 1 2 3 3 6 4 10 5 15 6 21 */ #include #include #define N 3 int sum(int n) { int res; printf("At recursive call %d\n", n); if(n == 1) //base case return 1; res = sum(n-1); printf("in call %d, returned from call %d with value %d\n", n, n-1, res); return n + res; //recursive case } int main() { int x; x = sum(N); printf("\n\nsum of %d down to 1 is %d\n\n", N, x); system("pause"); }