// Example program
#include <iostream>
using namespace std;
bool isFibonacci( int n, int a = 1, int b = 1 )
{
if(n == 0 || n == 1 ) return true;
int nextFib = a + b;
if( nextFib > n ) return false;
if( nextFib == n ) return true;
return isFibonacci( n, b, nextFib );
}
int main()
{
for(int i = 0; i<=10; ++i)
{
if(isFibonacci( i))
cout << i << " ";
}
}
#include <iostream>
using namespace std;
bool isFibonacci( int n, int a = 1, int b = 1 )
{
if(n == 0 || n == 1 ) return true;
int nextFib = a + b;
if( nextFib > n ) return false;
if( nextFib == n ) return true;
return isFibonacci( n, b, nextFib );
}
int main()
{
for(int i = 0; i<=10; ++i)
{
if(isFibonacci( i))
cout << i << " ";
}
}
Comment