This commit is contained in:
Ingy döt Net 2013-10-27 22:24:23 +00:00
parent 6f050a029e
commit 776bba907c
3887 changed files with 59894 additions and 7280 deletions

View file

@ -0,0 +1,63 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. show-lcm.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
REPOSITORY.
FUNCTION lcm
.
PROCEDURE DIVISION.
DISPLAY "lcm(35, 21) = " FUNCTION lcm(35, 21)
GOBACK
.
END PROGRAM show-lcm.
IDENTIFICATION DIVISION.
FUNCTION-ID. lcm.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
REPOSITORY.
FUNCTION gcd
.
DATA DIVISION.
LINKAGE SECTION.
01 m PIC S9(8).
01 n PIC S9(8).
01 ret PIC S9(8).
PROCEDURE DIVISION USING VALUE m, n RETURNING ret.
COMPUTE ret = FUNCTION ABS(m * n) / FUNCTION gcd(m, n)
GOBACK
.
END FUNCTION lcm.
IDENTIFICATION DIVISION.
FUNCTION-ID. gcd.
DATA DIVISION.
LOCAL-STORAGE SECTION.
01 temp PIC S9(8).
01 x PIC S9(8).
01 y PIC S9(8).
LINKAGE SECTION.
01 m PIC S9(8).
01 n PIC S9(8).
01 ret PIC S9(8).
PROCEDURE DIVISION USING VALUE m, n RETURNING ret.
MOVE m to x
MOVE n to y
PERFORM UNTIL y = 0
MOVE x TO temp
MOVE y TO x
MOVE FUNCTION MOD(temp, y) TO Y
END-PERFORM
MOVE FUNCTION ABS(x) TO ret
GOBACK
.
END FUNCTION gcd.

View file

@ -0,0 +1 @@
=LCM(A1:J1)

View file

@ -0,0 +1,3 @@
12 3 5 23 13 67 15 9 4 2
3605940

View file

@ -0,0 +1,24 @@
/* 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;

View file

@ -0,0 +1,5 @@
"%gcd%" <- function(u, v) {ifelse(u %% v != 0, v %gcd% (u%%v), v)}
"%lcm%" <- function(u, v) { abs(u*v)/(u %gcd% v)}
print (50 %lcm% 75)