38 lines
726 B
Text
38 lines
726 B
Text
Procedure isEven(x)
|
|
ProcedureReturn (x & 1) ! 1
|
|
EndProcedure
|
|
|
|
Procedure halveValue(x)
|
|
ProcedureReturn x / 2
|
|
EndProcedure
|
|
|
|
Procedure doubleValue(x)
|
|
ProcedureReturn x << 1
|
|
EndProcedure
|
|
|
|
Procedure EthiopianMultiply(x, y)
|
|
Protected sum, sign = x
|
|
|
|
Print("Ethiopian multiplication of " + Str(x) + " and " + Str(y) + " ...")
|
|
Repeat
|
|
If Not isEven(x)
|
|
sum + y
|
|
EndIf
|
|
x = halveValue(x)
|
|
y = doubleValue(y)
|
|
Until x = 0
|
|
If sign < 0 : sum * -1: EndIf
|
|
|
|
PrintN(" equals " + Str(sum))
|
|
ProcedureReturn sum
|
|
EndProcedure
|
|
|
|
If OpenConsole()
|
|
EthiopianMultiply(17,34)
|
|
EthiopianMultiply(-17,34)
|
|
EthiopianMultiply(-17,-34)
|
|
|
|
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit")
|
|
Input()
|
|
CloseConsole()
|
|
EndIf
|