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 operator is used to access a struct through a pointer a) >> b) -> c) *

864


What is the difference between #import and #include?

790


What does scope resolution operator do?

814


Can constructor be private in c++?

786


How can you quickly find the number of elements stored in a static array?

857


Please explain the reference variable in c++?

813


What is the c++ programming language used for?

775


What is an html tag?

835


What is a sequence in c++?

779


Is c++ a float?

811


What are the two shift operators and what are their functions?

827


What is main function in c++ with example?

844


What is bubble sort c++?

785


Write a code/algo to find the frequency of each element in an array?

842


What is the use of object in c++?

831