Write the program for fibonacci in c++?
Answer Posted / smita
#include<iostream.h>
#include<conio.h>
class fibonacci
{
int f0,f1,f2;
public:
fibonacci()//constructor
{
f0=0;
f1=1;
f2=f0+f1;
}
void cal()
{
f0=f1;
f1=f2;
f2=f0+f1;
}
void dis()
{
cout<<"fibonacci:"<<f2<<endl;
}
};
void main()
{
fibonacci obj;
int n;
cout<<"How many no. displayed:"<<endl;
cin>>n;
for(int i=0;i<=n-1;i++)
{
obj.dis();
obj.cal();
}
getch();
}
| Is This Answer Correct ? | 57 Yes | 34 No |
Post New Answer View All Answers
What does iomanip mean in c++?
When the constructor of a base class calls a virtual function, why doesn't the override function of the derived class gets called?
Explain the scope of resolution operator.
What happens when you make call 'delete this;'?
What is protected inheritance?
What is time h in c++?
What is a dangling pointer in c++?
Why is polymorphism useful?
What programming language should I learn first?
What is a tree in c++?
What is late binding c++?
What is the difference between mutex and binary semaphore?
What is singleton pattern in c++?
What is the maximum combined length of command line arguments including the space between adjacent arguments?
Which one between if-else and switch is more efficient?