//Using constructor development of Fibonacci series
#include<iostream.h>
#include<conio.h>
class fibo
{
private:
long int f0,f1,fib;
public:
fibo();//constructor
void increment();
void display();
};//end of class
fibo::fibo()
{
f0=0;
f1=1;
fib=f0+f1;
}
void fibo::increment()
{
f0=f1;
f1=fib;
fib=f0+f1;
}
void fibo::display()
{
cout<<fib<<"\t";
}
void main()
{
clrscr();
fibo no;
int i;
for(i=0;i<=15;i++)
{
no.display();
no.increment();
}
getch();
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.