Fibonacci Series Using Operator Overloading C++
Fibonacci Series Using Operator Overloading C++ in Object Oriented (OOP).
Program of Fibonacci Series with Operator Overloading
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
//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