Iterative Fibonacci algorithm giving me a wrong result after fib(47)

前端 未结 3 1929
旧巷少年郎
旧巷少年郎 2020-12-11 13:43

I am using the iterative fib algorithm that I have copied below. I have found this algorithm on Rosetta code and it gives me the correct answer up until fib(46). After that

3条回答
  •  攒了一身酷
    2020-12-11 14:03

    Make your variables long long instead of int. 'int' depending on the machine could be 64, 32, 16 or 8-bits.

    If you want to specify the size of the integer yourself and make a portable code then make use of uint8_t, uint16_t, etc or int8_t, int16_t, etc. The 'u' stands for unsigned. This is a part of the stdint.h library!

提交回复
热议问题