...
In C89 (and historical K&R implementations), the meaning of the remainder operator for negative arguments was implementation-defined, but was fixed in the C99 Standard.
...
The C99 definition of % operator implies the following behavior:
| Code Block |
|---|
17 % 3 -> 2
17 % -3 -> 2
-17 % 3 -> -2
-17 % -3 -> -2
|
...