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

How many static variables are created if you put one static member into a template class definition?

564


Are there any special rules about inlining?

579


What is implicit pointer in c++?

598


How can a called function determine the number of arguments that have been passed to it?

655


Explain what happens when a pointer is deleted twice?

731






What is a v-table?

643


What is the word you will use when defining a function in base class to allow this function to be a polimorphic function?

668


Differentiate between a copy constructor and an overloaded assignment operator.

637


Can circle be called an ellipse?

630


Explain virtual class and friend class.

595


Explain mutable storage class specifier.

622


What is the operator in c++?

622


What is c++ manipulator?

551


Is swift faster than c++?

557


How do you establish a has-a relationship?

607