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
How is c++ different from java?
Does c++ support exception handling?
Why do we need c++?
Can I learn c++ without knowing c?
What is the basic difference between C and C++?
write a corrected statement in c++ so that the statement will work properly. x = y = z + 3a;
What is abstraction in c++?
What are manipulators in c++ with example?
What is purpose of abstract class?
Why Pointers are not used in C++?
Array base access faster or pointer base access is faster?
Explain shallow copy?
Can comments be longer than one line?
What is c++ good for?
Explain bubble sorting.