summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2022-11-12 23:35:43 +0200
committerIgor Pashev <pashev.igor@gmail.com>2022-11-13 00:08:57 +0200
commit1414da584a1953172ce9e92a91e3fb2a86bbf59e (patch)
treee9f52be02b4ac0bf5de22220849f554f63349232
parentf8b0cf38d1f62e3f012a086513aa73952fbb9b3b (diff)
downloadgcd-1414da584a1953172ce9e92a91e3fb2a86bbf59e.tar.gz
Add COBOL
-rw-r--r--gcd.cob42
1 files changed, 42 insertions, 0 deletions
diff --git a/gcd.cob b/gcd.cob
new file mode 100644
index 0000000..b6ce0db
--- /dev/null
+++ b/gcd.cob
@@ -0,0 +1,42 @@
+ * Tested with GNU COBOL 4
+ *
+ * Synopsis:
+ *
+ * $ cobc -x gcd.cob -o gcd-cob
+ * $ ./gcd-cob 11 22 33 121
+ *
+ IDENTIFICATION DIVISION.
+ PROGRAM-ID. GCD.
+ DATA DIVISION.
+ WORKING-STORAGE SECTION.
+ 01 WS-COUNT PIC 9(20).
+ 01 WS-GCD PIC Z(20).
+ 01 WS-NUM PIC 9(20).
+ PROCEDURE DIVISION.
+ ACCEPT WS-COUNT FROM ARGUMENT-NUMBER.
+ IF WS-COUNT = 0 STOP RUN.
+ ACCEPT WS-GCD FROM ARGUMENT-VALUE.
+ PERFORM WITH TEST BEFORE UNTIL WS-COUNT = 1
+ ACCEPT WS-NUM FROM ARGUMENT-VALUE
+ CALL 'GCD2' USING WS-GCD, WS-NUM
+ SUBTRACT 1 FROM WS-COUNT
+ END-PERFORM.
+ DISPLAY FUNCTION TRIM (WS-GCD LEADING).
+ END PROGRAM GCD.
+
+ IDENTIFICATION DIVISION.
+ PROGRAM-ID. GCD2.
+ DATA DIVISION.
+ WORKING-STORAGE SECTION.
+ 01 WS-C PIC 9(20).
+ LINKAGE SECTION.
+ 01 L-A PIC Z(20).
+ 01 L-B PIC 9(20).
+ PROCEDURE DIVISION USING L-A, L-B.
+ PERFORM WITH TEST BEFORE UNTIL L-B = 0
+ MOVE L-B TO WS-C
+ DIVIDE WS-C INTO L-A GIVING L-A REMAINDER L-B
+ MOVE WS-C TO L-A
+ END-PERFORM.
+ END PROGRAM GCD2.
+