Question #57833

write a program that inputs a number from the user and displays fibonacci series up to the number entered

Expert's answer

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;
}
LATEST TUTORIALS
APPROVED BY CLIENTS