I implemented a function that prints all the numbers from the Fibonacci sequence until max_num
. The minimum value allowed is 0 (so, fib(0) prints 1). It works until 92, and I want to know how to improve the code, in general.
void fib(unsigned int max_num)
{
unsigned long fib_num = 1;
unsigned long fib_temp = 0;
size_t count = 0;
if (max_num < 0)
{
fprintf(stderr, "Please, enter a non-negative number\n");
return;
}
for (; count <= max_num; count++)
{
printf("%lu\n", fib_num);
fib_num += fib_temp;
fib_temp = fib_num - fib_temp;
}
}