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 do you mean by overhead in c++?
What is a set in c++?
Why can’t you call invariants() as the first line of your constructor?
Can a program run without main function?
What is the difference between a "copy constructor" and an "assignment operator" in C++?
Define the process of error-handling in case of constructor failure?
What are the two types of polymorphism?
What is a container class? What are the types of container classes in c++?
Are there interfaces in c++?
What is encapsulation in c++ with example?
Differentiate between a copy constructor and an overloaded assignment operator.
What is token c++?
Is c++ platform dependent?
What is setf in c++?
How many ways can a variable be initialized into in C++?