//Note: If you are not using Borland or Turbo C then add the following line after header files :
//using namespace std;
#include<conio.h>
#include<iostream.h>
class Fibonacci // fibonacci => 0 1 1 2 3 5 8 ......... upto n
{
int n,s,j; // n=no
public:
void fibo()
{
cout<<"\n Enter NUMBER:";
cin>>n;
cout<<endl;
s=0;
int p=1;
cout<<" Fibonacci series => \n\n";
cout<<s<<"\t";
cout<<p<<"\t";
cout<<p<<"\t";
while(j<n)
{
s=p;
p=j;
j=s+p; // adding previous values
cout<<j<<"\t";
}
}
};
int main()
{
Fibonacci obj;
obj.fibo();
getch();
return(0);
}
0 Comments