PROGRAM TO PRINT FIBONACCI SERIES UPTO N TERMS

/*PROGRAM TO PRINT FIBONACCI SERIES UPTO N TERMS*/

#include<conio.h>

#include<iostream.h>

class fib_series

{

int n,a,b,i,c;

public:

void input();

void output();

};

void fib_series::input()

{

cout<<“Enter limit of the series: “;

cin>>n;

}

void fib_series::output()

{

if(n>0)

{

a=-1;

b=1;

cout<<“First “<<n<<” terms of fibonacci series are:\n”;

for(i=1;i<=n;i++)

{

c=a+b;

cout<<c<<”  “;

a=b;

b=c;

}

}

else

cout<<“Limit must be greater than zero”;

}

void main()

{

fib_series f1;

clrscr();

f1.input();

f1.output();

getch();

}

Leave a Reply

Your email address will not be published. Required fields are marked *