Fibonacci Sequence in C generating negatives?

后端 未结 3 1254
借酒劲吻你
借酒劲吻你 2020-12-12 00:28

I\'m new to programming and need help in C. I am writing a program to generate a Fibonacci sequence for values with up to 1000 digits.

Here is my code:



        
3条回答
  •  旧时难觅i
    2020-12-12 01:03

    you are not using the correct data type; fibonacci numbers tend to grow really fast. So you probably are going beyond the limit for int: 2^31. Since int and long are both 32 bit integers (in most cases ->gcc and VS) try using long long .

提交回复
热议问题