Skip to main content
3 of 5
added 295 characters in body
user692992
  • 268
  • 1
  • 7
  1. The Fibonacci series shall never yield non whole numbers; doubles are unnecessary and possibly computationally expensive. Try a uintmax_t. It will probably give you values of up to 2^64 - 1 (18,446,744,073,709,551,615). That should certainly be sufficient. Additionally, I would put in code to terminate the program as it reaches the upper limit of uintmax_t.
  2. Your could have a classic I/O problem: output buffering. Try to put a \n in every print statement to encourage proper flushing. So rather than having the come at the beginning of each print statement, try putting it at the end. If you like it the way it is, you can call fflush(stdout) after every printf(). While we're on the topic, your first two printf() statements can be combined. More info at this SO question.
  3. Obviously the Sleep() functions are unnecessary to your code. I presume that they are there for the aesthetic value of the output, but I would take them out. Doing so would make your code OS-independent as well as neater. But obviously, depending on the assignment, appearance may be above all.
  4. Finally, despite the mathematical purpose of the program, math.h is not needed.

Addendum: You asked how to make it more professional. You could make a Fibonacci function returning always the next value based on static/global variable(s). You could then put the prettiness of sleeping and the welcome message in main() while maintaining the purity of your algorithm.

user692992
  • 268
  • 1
  • 7