If N
is a positive integer and d
is a positive integer then
(N/d) * d + N%d == N
For example
(5/2) * 2 + 5%2 == 5
This also works with negative integers. What is written by the following?
#include <stdio.h> /* Puzzle E08 -- negative modulo */ int main() { printf("Expression evaluates to: %d\n", (-5/2)*2 + (-5%2) ); return 0; }