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 destructors?
What is the copy-and-swap idiom?
What is the difference between C and CPP?
What causes a runtime error c++?
How do I exit turbo c++?
What is the fastest c++ compiler?
What is ifstream c++?
What is a volatile variable in c++?
Comment on local and global scope of a variable.
Can I learn c++ as my first language?
What is an inclusion guard?
How is new() different from malloc()?
Which bit wise operator is suitable for putting on a particular bit in a number?
What does the following do: for(;;) ; a) Illegal b) Loops forever c) Ignored by compiler...not illegal
Explain what is polymorphism in c++?