c99 standard says that result of modulo operation has same sign as first operand. So -9 % 7 = -2 and 9 % -7 = 2.
I read in one book that c89 standard depends on implementation. So -9 % 7 could yield -2 or 5??? How remainder of -9 / 7 could be 5?
Consider two numbers
aandb.The quotient
q=a/band remainderr=a%bsatisfy the equationa == q*b + r.An (hypothetical) implementation of C89 in which -9 % 7 produces 5 is an implementation in which -9 / 7 is computed as -2.
The mathematical (Euclidian) division constrains
rto be positive and smaller thanb. C99 constrains it to be of the same sign asaand strictly between-bandb.It is all only a matter of convention.