//fibonacci series using increment operator overloading
#include<iostream.h>
#include<conio.h>
class fibo
{
int a,b,c;
public:
fibo()
{
a=-1;
b=1;
c=a+b;
}
void display()
{
cout<<c<<" ";
}
void operator++()
{
a=b;
b=c;
c=a+b;
}
};
void main()
{
int n,i;
fibo f;
clrscr();
cout<<"Enter the limit of the series: ";
cin>>n;
for(i=0;i<n;i++)
{
f.display();
f++;
}
getch();
}
#include<iostream.h>
#include<conio.h>
class fibo
{
int a,b,c;
public:
fibo()
{
a=-1;
b=1;
c=a+b;
}
void display()
{
cout<<c<<" ";
}
void operator++()
{
a=b;
b=c;
c=a+b;
}
};
void main()
{
int n,i;
fibo f;
clrscr();
cout<<"Enter the limit of the series: ";
cin>>n;
for(i=0;i<n;i++)
{
f.display();
f++;
}
getch();
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.