34 lines
635 B
C++
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";
|
||
|
}
|
||
|
}
|