Write the program for fibonacci in c++?
Answer Posted / gobinath
#include<iostream>
using namespace std;
class A
{
public:
void print()
{
int a=0,b=1,c=0,n;
cout<<"Enter the number of : "<<endl;
cin>>n;
cout<<a<<" "<<b<<" ";
for(int i=1;i<=n-2;i++)
{
c=a+b;
a=b;
b=c;
cout<<c<<" ";
}
}
};
int main()
{
A a;
a.print();
}
| Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
What is difference between n and endl in c++?
What are the advantages of using pointers in a program?
What is c++ mutable?
Describe the setting up of my member functions to avoid overriding by the derived class?
What is the arrow operator in c++?
What is function prototyping?
What is the meaning of c++?
We all know that a const variable needs to be initialized at the time of declaration. Then how come the program given below runs properly even when we have not initialized p?
What is the difference between public and private data members?
Why should we use null or zero in a program?
If a round rectangle has straight edges and rounded corners, your roundrect class inherits both from rectangle and from circle, and they in turn both inherit from shape, how many shapes are created when you create a roundrect?
Why would you use pointers in c++?
Define pointers?
What does floor mean in c++?
List down the guideline that should be followed while using friend function.