The following program in C takes n as an input and finds the sum of the series up to nth term using recursion. The series is given below: (1 x 3) + (2 x 5) + (4 x 7) + (8 x 9) + ... + nth term
Here is my code:
#include <stdio.h>
#include <math.h>
int addNumbers(int n);
int main(){
int n;
printf("Enter a positive integer n: ");
scanf("%d", &n);
printf("Sum = %d", addNumbers(n));
return 0;
}
int addNumbers(int n){
if (n>0)
return pow (2, n-1)*(2*n+1)+addNumbers(n-1);
else
return n;
}
How can I show the simulation of the recursion for n=5 in my code?