Ethiopian multiplication: Difference between revisions
Content added Content deleted
(→{{header|PureBasic}}: changed isOdd() to isEven()) |
|||
Line 1,235: | Line 1,235: | ||
=={{header|PL/I}}== |
=={{header|PL/I}}== |
||
{{incorrect|PL/I|program needs to define three functions to halve double and test odd/even as stated in the task description.}} |
|||
<lang PL/I> |
<lang PL/I> |
||
declare (L(30), R(30)) fixed binary; |
declare (L(30), R(30)) fixed binary; |
||
Line 1,242: | Line 1,241: | ||
L, R = 0; |
L, R = 0; |
||
put skip list |
put skip list |
||
(' |
('Hello, please type two values and I will print their product:'); |
||
get list (L(1), R(1)); |
get list (L(1), R(1)); |
||
put edit ('The product of ', trim(L(1)), ' and ', trim(R(1)), ' is ') (a); |
put edit ('The product of ', trim(L(1)), ' and ', trim(R(1)), ' is ') (a); |
||
do i = 1 by 1 while (L(i) ^= 0); |
do i = 1 by 1 while (L(i) ^= 0); |
||
L(i+1) = L(i) |
L(i+1) = halve(L(i)); |
||
R(i+1) = R(i) |
R(i+1) = double(R(i)); |
||
end; |
end; |
||
s = 0; |
s = 0; |
||
do i = 1 by 1 while (L(i) > 0); |
do i = 1 by 1 while (L(i) > 0); |
||
if |
if odd(L(i)) then s = s + R(i); |
||
end; |
end; |
||
put edit (trim(s)) (a); |
put edit (trim(s)) (a); |
||
halve: procedure (k) returns (fixed binary); |
|||
declare k fixed binary; |
|||
return (k/2); |
|||
end halve; |
|||
double: procedure (k) returns (fixed binary); |
|||
declare k fixed binary; |
|||
return (2*k); |
|||
end; |
|||
odd: procedure (k) returns (bit (1)); |
|||
return (iand(k, 1) ^= 0); |
|||
end odd; |
|||
</lang> |
</lang> |
||