C语言中整除问题 C语言中,当除数、被除数和商都定义成int型时,如不能整除,商会自动转换成int类型。 那么,C语言是不是默认舍去小数部分,不论小数部分是否足够大? 如,10/3=3,舍去了小数部分;-10/3=-3,舍去了小数部分。 我试了试编译这两个例子,结果是这样。 对不对?我不太肯定 c [解决办法]
When integers are divided and the division is inexact, if both operands are positive the result of the / operator is the largest integer less than the algebraic quotient and the result of the % operator is positive. If either operand is negative, whether the result of the / operator is the largest integer less than the algebraic quotient or the smallest integer greater than the algebraic quotient is implementation-defined, as is the sign of the result of the % operator. If the quotient a/b is representable, the expression (a/b)*b + a%b shall equal a.