Program to print “Fibonacci series” up to n.

It is a series starting from 0 or sometimes from 1 whose subsequent number is the sum of the previous two numbers.                                                                                              Example :-

0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765………

Source code:

#include <iostream>
#include<conio.h>
#include<iomanip>

using namespace std;

int main()
{
    long int i,f1=0,f2=1,f3,number;
    cout<<"Enter number :";cin>>number;cout<<endl;
    if(number>=1)
        cout<<"0"<<endl;
    if(number>=2)
        cout<<"1"<<endl;

    for(i=3;i<=number;i++)
    {
        f3=f1+f2;
        cout<<f3<<endl;
        f1=f2;
        f2=f3;
    }
    getch();
}

  

Leave a comment