A program to display the following series ( i.e. Fibnocci Series ) :

                    0    
                    1 1  
                    2 3 5  
                    8 13 21 34  
                    55...........n   

where n is the limit of the series entered by the user.

 

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a=0,b=1,c,d=2,e,n;

cout<<"Enter limit: ";
cin>>n;

c=a+b;

if(n>=0)
cout<<a<<"\n";
if(n>=1)
cout<<b<<" "<<c<<"\n";

while(c<n)
{
d=d+1;
for(e=1;e<=d;e++)
{
a=b;
b=c;
c=a+b;
if(c<=n)
cout<<c<<" ";
}
cout<<"\n";
}

getch();
}

 

< Back