Write the program for fibonacci in c++?

Answer Posted / dudelzy

Simplest one:

#include <iostream>

using namespace std;

int main()
{
int x, a = 0, b = 1, i, z;
cout << "Lets Start!" << endl;
cout << "No. of elements in the series = ";
cin >> x;
cout << "Series: " << endl;
for(i = 0; i < x; i++){
z = a + b;
a = b;
b = z;
cout << z << endl;
}

return 0;
}

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is rvalue?

682


What are static type checking?

634


What is a memory leak c++?

592


Give 10 points of differences between C & C++.

631


What is setiosflags c++?

537






What does extern mean in a function declaration in c++?

706


What is anonymous object in c++?

632


Can you sort a set c++?

532


How does c++ sort work?

568


Do you need a main function in c++?

561


Difference between a copy constructor and an assignment operator.

580


What are single and multiple inheritances in c++?

581


What does new do in c++?

639


What is the function to call to turn an ascii string into a long?

605


What is the benefit of learning c++?

555