‘C’ program to display n terms of the Fibonacci series.
C File =>
/* Write a ‘C’ program to display n terms of the Fibonacci series. */
#include<stdio.h>
int main()
{
int n,i,a=0,b=1,c;
printf("\n Enter value of n : ");
scanf("%d",&n);
if(n==1)
printf("\n %d",a);
else if(n==2)
printf("\n%d\t%d",a,b);
else if(n>2)
{
printf("\n%d\t%d\t",a,b);
for(i=3;i<=n;i++)
{
c=a+b;
printf("%d\t",c);
a=b;
b=c;
} //end for
}
return 0;
}
Comments
Post a Comment
Please do not enter any spam link in message.