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();
}

  
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s