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
Is c++ the best programming language?
What is an object in c++?
What is c++ course?
Which programming language is best?
Is map ordered c++?
If all is successful, what should main return a) 0 b) 1 c) void
Show the application of a dynamic array with the help of an example.
What is an iterator class in c++?
What is the difference between public and private data members?
Does std endl flush?
What is the prototype of printf function?
What does std mean in c++?
Does there exist any way to make the command line arguments available to other functions without passing them as arguments to the function?
What is setw manipulator in c++?
What is ios flag in c++?