How to Print Fibonacci Series In C

Click Image To ZOOM

//Code
#include<stdio.h>
main()
{
int a,b,c,i,n;
a=0;b=1;
printf("Enter No Upto Display Fibonacci Series\n");
scanf("%d",&n);
printf("\n%d\n%d\n",a,b);
for(i=0;i<n-2;i++)
{
c=a+b;
a=b;   /*after a=0,b=1,we have sum c=1,now to add b&c for series in loop
       just change b to a and c to b*/
    b=c;
    
printf("%d\n",c);
}

}

No comments:

Post a Comment