Answer to Question #57833 in C++ for Ali hassan

Question #57833
write a program that inputs a number from the user and displays fibonacci series up to the number entered
1
Expert's answer
2016-02-17T05:37:29-0500
Answer on Question#57833 — Programming | C++

#include <iostream>
using namespace std;

int main() {
int n, first = 0, second = 1, next = 1;
cin >> n;
if (n > 1) cout << 1 << endl;

while (next < n) {
next = first + second;
first = second;
second = next;
if (next < n) cout << next << endl;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS