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 pure virtual function?
What can c++ be used for?
What's the "software peter principleā?
Do you know what is overriding?
List the merits and demerits of declaring a nested class in C++?
What is time_t c++?
Does c++ have finally?
How would you differentiate between a pre and post increment operators while overloading?
Is there structure in c++?
How can a struct in c++ differs from a struct in c?
What are virtual constructors/destructors?
What is a linked list in c++?
What are the characteristics of friend functions?
How can you link a c++ program to c functions?
Refer to a name of class or function that is defined within a namespace?