Techknow Study

Fibonacci Sequence

7:31:00 PM vikas 0 Comments Category :

Fibonacci Sequence

            The Fibonacci Sequence is the series of numbers:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...


The next number is found by adding up the two numbers before it.
  • The 2 is found by adding the two numbers before it (1+1)
  • Similarly, the 3 is found by adding the two numbers before it (1+2),
  • And the 5 is (2+3),
  • and so on!
Example: the next number in the sequence above would be 21+34 = 55


program
#include<stdio.h>
#include<conio.h>
void main()
{
int  n,f1=0,f2=1,f3;
clrscr();
printf("enter no upto which u want series:");
scanf("%d",&n);
printf("%d %d",f1,f2);
f3=f1+f2;
while(f3<=n)
{
printf(" %d ",f3);
f1=f2;
f2=f3;
f3=f1+f2;
}
getch();
}


RELATED POSTS

0 comments