Just so we talk the same language:
- quotient = result of divide
- dividend = the number being divided
- divisor = the number you divide by
In other words: quotient = dividend/divisor;
I'm assuming you are doing integer math - the principle is pretty much the same if you have a decimal point, but you have to "slide" the decimal point along when you follow these steps.
The general principle for stringwise divide is:
- initialize temp quotient = 1
initialize final quotient = 0
Multiply the divisor by 10 until it's length is equal to the dividend
- /* multiply by 10 = insert zero at end of string */
- at the same time, multiply the temp quotient by 10.
if divisor > dividend, divide temp quotient and divisor by 10.
as long as divisor < dividend
- subtract divisor from dividend
- add temp quotient to final quotient.
If dividend > 0, go to 4.
This is clearly not the most efficient method, but it's fairly simple, but it's not the worst either (that would be to subtract divisor as many times as you can from the dividend, and 1000000000 / 1 would take 1000000000 iterations - really large numbers would take "forever").