Based on usual arithmetic conversions, it will overflow as 10000 * 735625 + 14780
(out of int
's range) is trying to save into int
.
Integral promotions are performed on the operands as follows:
- If either operand is of type
unsigned long
, the other operand is converted to type unsigned long
.
- If preceding condition not met, and if either operand is of type
long
and the other of type unsigned int
, both operands are converted to type unsigned long
.
- If the preceding two conditions are not met, and if either operand is of type
long
, the other operand is converted to type long
.
- If the preceding three conditions are not met, and if either operand is of type
unsigned int
, the other operand is converted to type unsigned int
.
- If none of the preceding conditions are met, both operands are converted to type
int
.
To work out, you need to use long long
(with larger range) stead.
A simple way, as @JoachimIsaksson suggested, is to put LL
after 10000
to calculate with long long
's precision:
i = ( 10000LL * 735625 + 14780)/3652425;
See it live: http://ideone.com/pA2Pvm