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
It is that simple!
Here is a longer list:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, ...
Program
#include<stdio.h>
#include<conio.h>
void main()
{
int f1,f2,f3=0,n=0;
clrscr();
f1=0;
f2=1;
printf("enter the num");
scanf("%d",&n);
while(f3<n)
{
f3=f1+f2;
printf("%d\n",f3);
f1=f2;
f2=f3;
}
printf("Fibonacci series=%d",f3);
getch();
}
Output:
Enter the number 4
1
2
3
5
Fibonacci series=5
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
It is that simple!
Here is a longer list:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, ...
Program
#include<stdio.h>
#include<conio.h>
void main()
{
int f1,f2,f3=0,n=0;
clrscr();
f1=0;
f2=1;
printf("enter the num");
scanf("%d",&n);
while(f3<n)
{
f3=f1+f2;
printf("%d\n",f3);
f1=f2;
f2=f3;
}
printf("Fibonacci series=%d",f3);
getch();
}
Output:
Enter the number 4
1
2
3
5
Fibonacci series=5
Pankaj Gaikar is a
professional blogger
from Pune, India who writes on Technology, Android,
Gadgets, social media and latest tech updates at
Punk Tech
,
Being Android
&
Shake The Tech
. Email me
HERE
0 comments :
Post a Comment