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


Please Help Members By Posting Answers For Below Questions

How is c++ different from java?

775


Does c++ support exception handling?

795


Why do we need c++?

781


Can I learn c++ without knowing c?

798


What is the basic difference between C and C++?

838


write a corrected statement in c++ so that the statement will work properly. x = y = z + 3a;

1649


What is abstraction in c++?

935


What are manipulators in c++ with example?

789


What is purpose of abstract class?

791


Why Pointers are not used in C++?

802


Array base access faster or pointer base access is faster?

2035


Explain shallow copy?

788


Can comments be longer than one line?

812


What is c++ good for?

774


Explain bubble sorting.

819