0
Why is their sum output negative? What would be their correct sum?
2 Réponses
+ 5
The reason being that the array consist of "long" type values and they do not fall into the "int" range. So there occurs an overflow and almost all values get "negative" values when they are considered as "int" types.
So just change the "sum" and "x" types to long and it shall work fine.
+ 8
Use long to store big int:
https://code.sololearn.com/cf2L3uW3ae13/?ref=app