The task is to divide a number by 7 efficiently without using {/, *, -} operators.

Possible Solution:

The solution is to realize that we can do this operation by dividing number on 8 using shift operation X >> 3 = x/8 and utilizing modulus operator %.
The algorithm is to divide number by 8 continually, changing the number to to the sum of division and the remainder.


int Divide(int Number)
{
int value = 0;
while (Number > 7)
int temp = (Number >> 3);
value += temp;
Number = (Number % 8) + temp;
}
if (Number == 7) value++;
return value;
}








Answers and Comments