Monday 29 February 2016

Fibonacci Series C program

Fibonacci numbers:Each Fibonacci numbers is defined to be the sum of its two immediate previous terms, where as the first two number are 0 and 1.
The Fibonacci numbers are the numbers in the following integer sequence :
0 1 1 2 3 5 8 13 21 34 55 89 144. . . . .

Ans:

/*Programme to print Fibonacci numbers less than given user number*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int x,y,z,num;
 printf("Enter any last number of Fibonacci series : ");
 scanf("%d",&num);
 x=0;
 y=1;
 while(num>=x)
 {
    z=x+y;
    printf("%d\t",x);
    x=y;
    y=z;
 }
 getch();
 return 0;

}

Output:

Enter last number where goes to end Fibonacci series : 70


0  1  1  2  3  5  8  13  21  34  55


No comments:

Post a Comment

Ads Inside Post