The
numbers in the sequence
1 1 2 3 5 8 13 21 ……………………..
are called Fibonacci numbers.
After the first two numbers in the series, each number is the sum of the two
preceding numbers.
source file name: Fibnums.C
#include<stdio.h>
int main()
{
int a,b,sum,n,m;
//clrscr();
printf("\n enter m no for Fibonacci series:");
scanf("%d" ,&m);
printf(" \n First %d Fibonacci numbers: ",m);
a=0;
b=1;
n=1;
printf("\n %d ",b);
do
{
sum=a+b;
printf(" %d ",sum);
a=b;
b=sum;
n++;
}while(n<m);
//getch();
return 0;
}
output:
0 Comments
Post a Comment