Thursday, October 25, 2012

The Fibonacci Series In C Using Recurssion


//IN CASE OF DOUBT, COMMENT IT
# include<stdio.h>
int fibo(int n);
int r;
void main()
{
int i, j, k, l = 0;
scanf("%d",&j);
for(i = 0; i < j; i++)
{
for( k = 0; k <= i; k++)
{
l = fibo(k);
printf("%d ", l);
}
printf("\n");
}
}
int fibo(int n)
{
if(n == 0)
{
return (0);
}
else if(n == 1)
{
return (1);
}
else
{
r =  fibo(n- 1) + fibo(n-2);
return r;
}
}

2 comments:

  1. Check the condition...it is given that if n=0 or n=1 then we have to took value 0.

    ReplyDelete
    Replies
    1. the condition given to us is wrong. this condition will give the correct answer or the desired output. we were told to change the 0 to n

      Delete