RosettaCodeData/Task/Least-common-multiple/PL-I/least-common-multiple.pli
Ingy döt Net 776bba907c Sync
2013-10-27 22:24:23 +00:00

24 lines
613 B
Text

/* Calculate the Least Common Multiple of two integers. */
LCM: procedure options (main); /* 16 October 2013 */
declare (m, n) fixed binary (31);
get (m, n);
put edit ('The LCM of ', m, ' and ', n, ' is', LCM(m, n)) (a, x(1));
LCM: procedure (m, n) returns (fixed binary (31));
declare (m, n) fixed binary (31) nonassignable;
if m = 0 | n = 0 then return (0);
return (abs(m*n) / GCD(m, n));
end LCM;
GCD: procedure (a, b) returns (fixed binary (31)) recursive;
declare (a, b) fixed binary (31);
if b = 0 then return (a);
return (GCD (b, mod(a, b)) );
end GCD;
end LCM;