Skip to main content
Code Review

Return to Revisions

2 of 3
replaced http://stackoverflow.com/ with https://stackoverflow.com/

Consider documenting this function with something like Doxygen. At a quick glance, your function can be interpreted two different ways: Print out fib(0), fib(1), ..., or print out all Fibonacci numbers less than or equal to max_num. Documentation will clarify that.

max_num will never be negative. It is defined as an unisigned int, which means it can never hold a negative value. So this:

if (max_num < 0)
{
 fprintf(stderr, "Please, enter a non-negative number\n");
 return;
}

will never happen. (Try calling fib(-2), see what happens)

(Optional) Put size_t count = 0 inside the loop if you can? (You may have to add -std=c99 or something like that to make it work)

for (size_t count = 0; count <= max_num; count++)
{
 printf("%lu\n", fib_num);
 fib_num += fib_temp;
 fib_temp = fib_num - fib_temp;
}
Dair
  • 6.2k
  • 1
  • 21
  • 45
default

AltStyle によって変換されたページ (->オリジナル) /