C++ PROGRAMS
Fibonacci Series a series of numbers in which each number, Fibonacci number, is the sum of the two preceding numbers.
The simplest is the series 0,1, 1, 2, 3, 5, 8, etc.
The following program asks the user that how many Fibonacci numbers are required (minimum 3) and the output is the series till that number.
The program uses simple for-loop.
Code:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,n,i,sum;
cin>>n;
cout<<"Fibonacci Series: "<<"\n";
a=0;
b=1;
sum=0;
cout<<a<<"\n"<<b<<"\n";
for(i=1;i<=n-2;i++)
{
sum=a+b;
cout<<sum<<"\n";
a=b;
b=sum;
}
getch();
}
Output:
First Run:
Second Run: