Ethiopian multiplication: Difference between revisions

Add Seed7 ethiopian/peasant multiplication
No edit summary
(Add Seed7 ethiopian/peasant multiplication)
Line 1,224:
 
12 tests, 12 assertions, 0 failures, 0 errors</pre>
 
=={{header|Seed7}}==
 
Ethiopian Multiplication is another name for the peasant multiplication:
 
<lang seed7>const func integer: peasantMult (in var integer: a, in var integer: b) is func
result
var integer: result is 0;
begin
while a <> 0 do
if odd(a) then
result +:= b;
end if;
a := a div 2;
b *:= 2;
end while;
end func;</lang>
 
Original source: [http://seed7.sourceforge.net/algorith/math.htm#peasantMult]
 
=={{header|Smalltalk}}==
Anonymous user