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

What is pure virtual function?

621


What can c++ be used for?

578


What's the "software peter principleā€?

618


Do you know what is overriding?

615


List the merits and demerits of declaring a nested class in C++?

607






What is time_t c++?

606


Does c++ have finally?

565


How would you differentiate between a pre and post increment operators while overloading?

650


Is there structure in c++?

585


How can a struct in c++ differs from a struct in c?

608


What are virtual constructors/destructors?

576


What is a linked list in c++?

540


What are the characteristics of friend functions?

559


How can you link a c++ program to c functions?

617


Refer to a name of class or function that is defined within a namespace?

601