#include<stdio.h>
int main()
{
int a=0,b=1,num,c,count;
printf("Enter
a number to obtain fibonacci series\n");
scanf("%d",&num);
printf("The
series is\n");
printf("%d
\n%d\n",a,b);
count=2;
while(count<num)
{
c=a+b;
a=b;
b=c;
printf("%d\n",c);
count++;
}
return 0;
}
Enter your comment... pls explain me i got confused
ReplyDeleteInitially Fibonacci series starts with 0 1 1 2 3 5 and so on
ReplyDeleteexpressed as xn = xn-1 + xn-2.
A=0,B=1;
Here initially we print 0 1 after that adding both 0&1 store in C variable. Print C value as 3rd Fibonacci
number. After that swapping B value to
A and new value obtained by (C=A+B) to be stored in B. this condition fails until count<given length.
New value found is just swapped to B.before that old value of B is swapped to A.