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
State the difference between delete and delete[].
Define whitespace in C++.
What is constructor c++?
What are the advantages of early binding?
What do you mean by friend class & friend function in c++?
Which is better turbo c++ or dev c++?
Explain what are the sizes and ranges of the basic c++ data types?
What is microsoft c++ redistributable 2013?
Why do we use double in c++?
What are register variables?
What is a vector c++?
What is #include cstdlib in c++?
What is the need of a destructor? Explain with the help of an example.
Is c++ the hardest programming language?
Comment on assignment operator in c++.