27 lines
609 B
Text
27 lines
609 B
Text
DIM table(32, 2)
|
|
dividend = 580
|
|
divisor = 34
|
|
|
|
i = 1
|
|
table(i, 1) = 1
|
|
table(i, 2) = divisor
|
|
|
|
WHILE table(i, 2) < dividend
|
|
i = i + 1
|
|
table(i, 1) = table(i - 1, 1) * 2
|
|
table(i, 2) = table(i - 1, 2) * 2
|
|
WEND
|
|
i = i - 1
|
|
answer = table(i, 1)
|
|
accumulator = table(i, 2)
|
|
|
|
WHILE i > 1
|
|
i = i - 1
|
|
IF table(i, 2) + accumulator <= dividend THEN
|
|
answer = answer + table(i, 1)
|
|
accumulator = accumulator + table(i, 2)
|
|
END IF
|
|
WEND
|
|
|
|
PRINT STR$(dividend); " divided by "; STR$(divisor); " using Egytian division";
|
|
PRINT " returns "; STR$(answer); " mod(ulus) "; STR$(dividend - accumulator)
|