0

Why does the code print negative numbers?

That is a fibonacci generator. On ~45 number prints negative. why? https://code.sololearn.com/cf2czO30H8JV/?ref=app

6th Jan 2018, 6:14 PM
Александр
Александр - avatar
2 Respostas
+ 12
The int datatype has a maximum value of (2 ^ 31) - 1 minimum value of -(2 ^ 31) , when your number reaches that it will drop to -(2 ^ 31) and start counting from there If my explanation confuses you let me explain with byte Byte can store numbers in the range -128 to 127 so this: byte x = 130 is effectively -126
6th Jan 2018, 6:44 PM
David Akhihiero
David Akhihiero - avatar
+ 10
Using long will work better
6th Jan 2018, 7:04 PM
David Akhihiero
David Akhihiero - avatar