Ethiopian multiplication: Difference between revisions

no edit summary
(Replaced all instances of EXIT PROGRAM to GOBACK)
No edit summary
Line 1,721:
}
}</lang>
 
=={{header|NetRexx}}==
{{trans|REXX}}
<lang NetRexx>/* NetRexx */
options replace format comments java crossref savelog symbols nobinary
 
/*REXX program multiplies 2 integers by Ethiopian/Russian peasant method*/
numeric digits 1000 /*handle extremely large integers. */
/*handles zeroes and negative integers.*/
/*A & B should be checked if integers.*/
parse arg a b .
say 'a=' a
say 'b=' b
say 'product=' emult(a,b)
return
method emult(x,y) private static
parse x x 1 ox
prod=0
loop while x\==0
if \iseven(x) then prod=prod+y
x=halve(x)
y=dubble(y)
end
return prod*ox.sign
 
method halve(x) private static
return x % 2
 
method dubble(x) private static
return x + x
 
method iseven(x) private static
return x//2 == 0
 
</lang>
 
=={{header|Object Pascal}}==
Line 1,962 ⟶ 1,998:
d
};</lang>
 
=={{header|ooRexx}}==
The [[#REXX|Rexx]] solution shown herein applies equally to [[ooRexx]].
 
=={{header|Pascal}}==
Anonymous user