The operator "%" in C is the remainder operator, not the modulo operator. (The operator "%" is in C + +, Java, for the remainder operation, and in Python for modulo operations)
For a C language to take the remainder expression a% B, set its value to result, has the following formula:
1. k = (int) A/b ((int) coercion type conversion, the value is rounded in 0 direction)
2. result = A-k * b
The difference between the modulus and the remainder: when the value of K is calculated, the rounding direction is different, the modulo operator takes the result of a/b to negative infinity, and the take-up operator takes the result of a/b to 0 trade-offs. (for example, the value of K when -4/3 is modulo is-2, and the value of K at the time of taking the remainder is-1)
Example:
The value of 13% 4 is calculated.
1. k = (int) 13/4 = 3
2. Result = 13-3 * 4 = 1
Therefore, its value is 1.
Note: The two operands of the remainder operator must all be integers, and the second operand cannot be zero.
Special cases:
When |a| < |b|, the value is always a.
When |a| = |b|, the value is always 0.
When a = 0 o'clock, the value is always 0.
C Language "%" operator