i have been asked to write a program to generate fibonacci as well as non fibonacci numbers till a certain value. i have just started learning c++. i managed to find the fibonacci series but i am unable to find the non fibo one. how do i go about with?? pls can anyone help me!

my code:

int fibonacci( int i )
int final[] = { 0, 1 };

while ( i > 1 )
int f = final[0];
final[0] = final[1];
final[1] = final[0] + f;

return final;
void main()
for ( int i = 0; i < 10; ++i )
cout << i << ": " << fibonacci( i ) << '\n';

One way is to generate a container containing all numbers 1 to x, then generate a container filled with all fibonocci numbers 1 to x, then all numbers that aren't fibonacci numbers in 1 to x go in a third container that will contain all nonfibonacci numbers 1 to x.

Define non fibonacci? It is a pretty loose definition.

Thanks lerner. but that is where i am getting stuck at the code. i mean at the third step where i basically have to filter out the non fibo numbers from the first container/array.

Just generate the non-Fibonacci series the same way you'd generate the Fibonacci series -- just print out all the numbers between your current and the previous one, instead of only the current. You don't need to fill any containers.

Save the first and second Fibonacci values (value1 and value2).

Loop, printing out all numbers between these values.

Move value2 to value1, generate the next Fib# stored into value2. Repeat the above loop.