//Fibonacci numbers to nth terms
#include<stdio.h>
#include<conio.h>
void main()
{ clrscr();
int a=0,n, b=1,c,count=0;
printf("enter the n th term:");
scanf("%d",&n);
printf("fibonacci numbers to %d term is :\n",n);
printf("%d\n",a);
printf("%d\n",b);
count=2; // first two Fibonacci numbers is used .
do
{
c=a+b;
printf("%d\n",c);
a=b;
b=c;
count++;
}
while(count<=n);
getch();
}
output:
enter the n th term:10
fibonacci number to 10 term is:
0
1
1
2
3
5
8
13
21
34
- Blogger Comment
- Facebook Comment
Subscribe to:
Post Comments
(
Atom
)
0 comments:
Post a Comment