0
Fibonacci Sequence Question
I made a program to calculate the value of a position in the Fibonacci Sequence but when i enter numbers like 200, some values tend to be negative. Why is that? Here's the link for the code: https://code.sololearn.com/c3YV2YRVxhvP/#cpp
12 Antworten
+ 3
That is a typical case of integer overflow, where the result of the addition is bigger than what can be stored inside a 32-bit integer variable, so the number is rolled back. Also see the following:
https://stackoverflow.com/questions/29235436/c-integer-overflow
+ 5
the value seems to be too big for an Integer variable. try with long or unsigned long.
+ 3
Absolutely agree Shadow... I don't seem to have the same issue in my Perl code
+ 2
Looks like an overflow issue.
+ 2
Oscar Ramírez Díaz stick around and learn from your peers and professionals. Some of us have been programming for decades while others for a year. By the time you get in out of University you should have numerous skillsets by the time you enter the workforce.
+ 1
Well, I don't know any Perl at all, but I guess it has some smarter integer handling then, BroFar. :)
+ 1
Here is my code even after stretching it out several times over attempting to reach an overflow.... Shadow
https://code.sololearn.com/cSB0ZKlT7fMR/?ref=app
+ 1
I'm learning for myself, I'm about to enter university, at which grade should I be able to do things like that?
+ 1
I mean like the code you did
0
Holly cow
0
Thanks Oscar Ramírez Díaz