Site icon T4Tutorials.com

Fibonacci Series Using Operator Overloading C++

Fibonacci Series Using Operator Overloading C++ in Object Oriented (OOP).

Program of Fibonacci Series with Operator Overloading

//PROGRAM in C++ to PRINT FIBONACCI SERIES USING INCREMENT OPERATOR OVERLOADING
#include<conio.h>
#include<iostream>
using namespace std;
class T4Tutorials
{
int a,b,c;
public:
T4Tutorials()
{
a=-1;
b=1;
c=a+b;
}
void show()
{
cout<<c<<" ";
}
void operator++()
{
a=b;
b=c;
c=a+b;
}
};
int main()
{
int n,i;
T4Tutorials f1;
cout<<"Please Enter the limit of the series: ";
cin>>n;
for(i=0;i<n;i++)
{
f1.show();
++f1;
}
getch();
}

Output

Please Enter the limit of the series: 4

0 1 1 2

Exit mobile version