Ethiopian multiplication: Difference between revisions

m
Adding MUMPS example
m (Adding MUMPS example)
Line 1,253:
IO.Put("17 times 34 = " & Fmt.Int(Multiply(17, 34)) & "\n");
END Ethiopian.</lang>
 
=={{header|MUMPS}}==
<lang MUMPS>
HALVE(I)
;I should be an integer
QUIT I\2
DOUBLE(I)
;I should be an integer
QUIT I*2
ISEVEN(I)
;I should be an integer
QUIT '(I#2)
E2(M,N)
New W,A,E,L Set W=$Select($Length(M)>=$Length(N):$Length(M)+2,1:$L(N)+2),A=0,L=0,A(L,1)=M,A(L,2)=N
Write "Multiplying two numbers:"
For Write !,$Justify(A(L,1),W),?W,$Justify(A(L,2),W) Write:$$ISEVEN(A(L,1)) ?(2*W)," Struck" Set:'$$ISEVEN(A(L,1)) A=A+A(L,2) Set L=L+1,A(L,1)=$$HALVE(A(L-1,1)),A(L,2)=$$DOUBLE(A(L-1,2)) Quit:A(L,1)<1
Write ! For E=W:1:(2*W) Write ?E,"="
Write !,?W,$Justify(A,W),!
Kill W,A,E,L
Q
</lang>
Output:<pre>
USER>D E2^ROSETTA(1439,7)
Multiplying two numbers:
1439 7
719 14
359 28
179 56
89 112
44 224 Struck
22 448 Struck
11 896
5 1792
2 3584 Struck
1 7168
=======
10073
</pre>
 
=={{header|Objective-C}}==