Any answer that doesn't use the operator %
will be a less efficient answer, but, if you absolutely cannot use the operator, then, one solution is to use a loop to subtract d from n repeatedly:
m = n;
while (m >= d)
{
m -= d;
}
Assuming that your integers are 32-bit, then you can consider an optimized version where we delete multiples of d from n:
m = n;
for (i = 31; i >= 0; i--)
{
di = d << i;
if (di > 0 && m >= di) m -= di;
}
This example, assumes the integers are signed and watches for overflow i.e. the test for di > 0
.