Using the code below you can
print as many numbers of terms of series as desired. Numbers of Fibonacci
sequence are known as Fibonacci numbers. First few numbers of series are 0, 1,
1, 2, 3, 5, 8 etc, Except first two terms in sequence every other term is the
sum of two previous terms, For example 8 = 3 + 5 (addition of 3, 5). This
sequence has many applications in mathematics and Computer Science.
#include<stdio.h>
#include<conio.h>
void main()
{
int n, a = 0, b = 1, t, c;
clrscr();
printf("Enter the number of terms\n");
scanf("%d",&t);
printf(“%2d\n %2d\n”,a,b);
n=3;
while(n<=t)
{
c=a+b;
printf(“%2d\n”,c);
a=b;
b=c;
n+=1;
}
getch();
}
Output of program:
No comments:
Post a Comment