199k views
9 votes
Write a c++ programm that enter a number from the user and displays Fibonacci numbers from 1 to given number using function

User Nverbeek
by
2.9k points

1 Answer

12 votes

Answer:

#include <iostream>

using namespace std;

int main()

{

cout << "Enter number: ";

int number;

cin >> number;

int prevfib = 0;

int fib = 1;

while (fib <= number) {

cout << fib << " ";

int add = prevfib;

prevfib = fib;

fib += add;

}

}

User Muarl
by
3.3k points