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

Given the following seqment of code containing a group of nested if instructions: y = 9; if ((x==3) || (x == 5)) y++; else if (x == 2) y *= 2; else if (x == ) y-= 7; else y = 8; if the value of x is 4 before the nested IFs are executed, what is the value of y after the nested IFs are executed?

1817


Write about c++ storage classes?

994


What is the difference between an external iterator and an internal iterator? Describe an advantage of an external iterator?

876


What is the identity function in c++? How is it useful?

811


What is the difference between global variables and local variable

765


What do you mean by late binding?

869


What is operator overloading in c++ example?

894


which one is equivalent to multiplying by 2:Left shifting a number by 1 or Left shifting an unsigned int or char by 1?

997


What do you mean by global variables?

875


Write a program to show polymorphism in C++?

871


What does std mean in c++?

830


If dog is a friend of boy and boy is a friend of house, is dog a friend of house?

778


What is time h in c++?

905


Evaluate the following expression as C++ would do :8 * 9 + 2 * 5 a) 82 b) 79 c) 370 d) list

831


What is const in c++?

846