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


Please Help Members By Posting Answers For Below Questions

Is c++ the best programming language?

745


What is an object in c++?

816


What is c++ course?

782


Which programming language is best?

747


Is map ordered c++?

819


If all is successful, what should main return a) 0 b) 1 c) void

780


Show the application of a dynamic array with the help of an example.

852


What is an iterator class in c++?

848


What is the difference between public and private data members?

878


Does std endl flush?

777


What is the prototype of printf function?

865


What does std mean in c++?

792


Does there exist any way to make the command line arguments available to other functions without passing them as arguments to the function?

979


What is setw manipulator in c++?

799


What is ios flag in c++?

871