|
Slide number 13, Chapter:12
// Returns the integer part of x / y,
// where x ≥ 0 and y > 0
// Strategy: repetitive subtraction
divide (x , y) :
div = 0
rem = x
while rem ≤ x
rem = rem – y
div = div + 1
return div
I think the while condition here should be rem>=y instead of rem<=x. Please, correct me if I am wrong.
If we divide 20/6
rem = 20-6=14
rem = 14-6 = 8
rem = 8-6 = 2
if rem<=x I don't understand how it works
if rem>=y the the condition will be false and we get the answer.
|