In an algorithm book once the first example was how to compute a multiplication in a loop (only that, so I just remembered, and wanted to do it programmatically but with all operations)


Multiplication was simple, say 10 \* 4:


base = 0, x = 10, y = 4:



```
While y != 0:
base + x = 10, y--
base + x = 20, y--
base + x = 30, y--
base + x = 40, y-- (y is now 0)

Result of base: 40 (correct)

```

As the opposite of taking away is giving, I assumed the same was for division and multiplication (doubling, halving), but: `"base - x.."` clearly does not give anything useful in an iteration..


Is this impossible? Am I looking at an algorithm to divide completely the wrong way (not like my mult)?



Mul + div using only add/sub ?
Division is repeated subtraction. Take 11 \div 3 as an example.


11 - 3 = 8.
Increment the quotient by 1.
Since 8 > 3, keep going.


8 - 3 = 5.
Increment the quotient by 1.
Since 5 > 3, keep going.


5 - 3 = 2.
Increment the quotient by 1.
Since 2 < 3, set the remainder to 2 and terminate.


I'll leave it to you to figure out the code.


