Jump to content

Ethiopian multiplication: Difference between revisions

(→‎{{header|PureBasic}}: changed isOdd() to isEven())
Line 1,235:
 
=={{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>
declare (L(30), R(30)) fixed binary;
Line 1,242 ⟶ 1,241:
L, R = 0;
put skip list
('helloHello, please type two values and I will print their product:');
get list (L(1), R(1));
put edit ('The product of ', trim(L(1)), ' and ', trim(R(1)), ' is ') (a);
do i = 1 by 1 while (L(i) ^= 0);
L(i+1) = halve(L(i)/2);
R(i+1) = double(R(i) * 2);
end;
s = 0;
do i = 1 by 1 while (L(i) > 0);
if iandodd(L(i), 1) ^= 0 then s = s + R(i);
end;
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>
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.