INF205/lab_1/3.cpp
2024-02-24 11:37:06 +01:00

34 lines
635 B
C++

#include <iostream>
#include <string>
int print_fibo_until(int x)
{
int n = 1;
int fibo_n = 1;
int fibo_previus = 0;
while(x >= fibo_n)
{
std::cout << std::to_string(n) + std::to_string(fibo_n) + "\n";
int fibo_next = fibo_n + fibo_previus;
n++;
fibo_previus = fibo_n;
fibo_n = fibo_next;
}
return (x==fibo_previus);
}
int main()
{
int y = 17711;
if(print_fibo_until(y))
{
std::cout << y;
std::cout << " is a Fibonacci number\n";
}
else
{
std::cout << y;
std::cout << " is not a Fibonacci number\n";
}
}