.
Home About-us Privacy Policy Contact-us Services

Friday, October 9, 2015

C++ Program to print the Fibonacci series by using prefix increment unary operator

ad+1

Program -


#include<iostream.h>
#include<conio.h>
class fibbo
{
Private:
unsigned long int i,j,k;
public:
fibbo()
{
i=0;j=1;k=i+j;
display();
{
cout<<i<<j;
}}
display()
{
cout<<"\n"<<k;
return(k);
}
void operator++()
{
i=j;j=k;k=i+j;
}
~fibbo()
{
cout<<"distroctor invoked";
}};
void main()
{
fibbo m;
int n,i;
cout<<"\n enter the value of n:";
cin>>n;
m.display();
for(i=1;i<n;i++)
{
m.display();
++m;
}
getch();
}

Output -


enter the value of n:9
1
1
2
3
5
8
13
21
34


0 comments:

Post a Comment

Home About-us Privacy Policy Contact-us Services
Copyright © 2014 All Programs Examples | All Rights Reserved. Blogger Templates Download Blogger Templates