Take the 2-minute tour ×
MathOverflow is a question and answer site for professional mathematicians. It's 100% free, no registration required.

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)?

share|improve this question

closed as off topic by Andrea Ferretti, Victor Protsak, José Figueroa-O'Farrill, Harald Hanche-Olsen, François G. Dorais Sep 12 '10 at 21:48

Questions on MathOverflow are expected to relate to research level mathematics within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

    
Take away x until you would go below zero. The number of times you took x away is the quotient. The number left is the remainder. Is this what you are looking for? Or do you want a decimal expansion of the fraction you get? By the way, you cannot multiply fractions using your algorithm - what is 1/2 times 1/3? Add 1/3 to itself repeatedly 1/2 a time? A computer would no take that instruction. –  Steven Gubkin Sep 12 '10 at 20:09
4  

1 Answer 1

up vote 0 down vote accepted

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.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.