Its giving me Integer Overflow both in java and C but when I tried it in Python it gave me right answer. Any reasons?
long long int a = 1000000011/2 * 5 ;
printf("%lld",a);
There are two reasons:
float f = 1 / 2;
you get 0, because the compiler performs integer division, without looking to see that you wanted to get a floating-point result. If you say long long int a = 1000000011/2 * 5;
you get an overflow, because the compiler performs integer arithmetic, without looking to see that you wanted to get a long long
result.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.