#include <stdio.h> //Static Var in Recursion
int fun1(int n)
{
 static int x=0;
 if(n>0)
 {
 x++;
 return fun(n-1)+x;
 }
 return 0;
}
int main() {
 int r;
 r=fun(5);
 printf("%d\n",r);

 r=fun(5);
 printf("%d\n",r);

 return 0;
}

//Global Var in Recursion
int x=0;
int fun2(int n)
{
 if(n>0)
 {
 x++;
 return fun(n-1)+x;
 }
 return 0;
}
int main() {
 int r;
 r=fun(5);
 printf("%d\n",r);

 r=fun(5);
 printf("%d\n",r);
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: