Sunday, 20 May 2012

Write a program to generate Fibonacci series up to given number of terms


 //program to print Fibonacci series upto 21
void main()
{
int a=-1,b=1,x,c;
clrscr();
printf("Enter a number ");
scanf("%d",x);
c=0;
while(c<=x)
{
c=a+b;
a=b;
b=c;
printf("%d\t",c);
}}
Output
Enter a number 13
0        1        1        2        3        5        8        13

No comments:

Post a Comment