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 are the advantages of early binding?
What is scope operator in c++?
Explain how an exception handler is defined and invoked in a Program.
What is using namespace std in c++?
What is friend class in c++ with example?
Can we inherit constructor in c++?
What is recursion?
What is #include ctype h in c++?
What is a far pointer? where we use it?
Can a constructor be private?
What is enum c++?
Does dev c++ support c++ 11?
Difference between a copy constructor and an assignment operator.
When does a name clash occur in c++?
Define namespace in c++?