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
How many static variables are created if you put one static member into a template class definition?
Are there any special rules about inlining?
What is implicit pointer in c++?
How can a called function determine the number of arguments that have been passed to it?
Explain what happens when a pointer is deleted twice?
What is a v-table?
What is the word you will use when defining a function in base class to allow this function to be a polimorphic function?
Differentiate between a copy constructor and an overloaded assignment operator.
Can circle be called an ellipse?
Explain virtual class and friend class.
Explain mutable storage class specifier.
What is the operator in c++?
What is c++ manipulator?
Is swift faster than c++?
How do you establish a has-a relationship?