here is another program where I am trying to to change to while loop into a recursion. I am trying to print a Fobannicci sequence
ex: 0,1,1,2,3,5,8,13.....
Any suggestions...because I am stuck!
Code:
long recursion(long k);
int main(int argc, char*argv[])
{
int n,k,f0,f1,f2;
if (argc==2) n=atoi(argv[1]);
else
{
perror("fib"); exit(1);
}
f0 = f1 = 1;
k=0;
printf("%2d %3d\n", 0, f0);
printf("%2d %3d\n", 1, f1);
printf("%2d %3d\n", k++, recursion(n));
return 0;
}
long recursion(long n)
{
int f0,f1,f2;
int k=2;
while (k<=n)
{
f2 = f0 + f1;
f0 = f1;
f1 = f2;
}
return f2;
}