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 are disadvantages of pointers?
What is the best book for c++ beginners?
What are friend functions in C++?
Explain the concept of friend function in c++?
How do I download c++?
Function can be overloaded based on the parameter which is a value or a reference. Explain if the statement is true.
Describe public access specifiers?
what is COPY CONSTRUCTOR and what is it used for?
What is an iterator class in c++?
What is the difference between global variables and static varables?
Is c++ built on c?
What are pointer-to-members in C++? Give their syntax.
What is the use of lambda in c++?
Can you pass a vector to a function?
Explain the purpose of the keyword volatile.