コンテンツにスキップ

英文维基 | 中文维基 | 日文维基 | 草榴社区

利用者:騏驎/COBOL

000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID. GETGCDTXT.
000300 ENVIRONMENT DIVISION.
000400 INPUT-OUTPUT SECTION.
000500 FILE-CONTROL.
000600     SELECT INDATA ASSIGN TO 'INDATA.TXT'
000700       ORGANIZATION IS LINE SEQUENTIAL FILE STATUS IS INDATA-STS.
000800     SELECT OTDATA ASSIGN TO 'OTDATA.TXT'
000900       ORGANIZATION IS LINE SEQUENTIAL.
001000 DATA DIVISION.
001100 FILE SECTION.
001200 FD INDATA.
001300 01 INDATA-REC.
001400     03 M        PIC 9(18).
001500     03 FILLER   PIC X(01).
001600     03 N        PIC 9(18).
001700 FD OTDATA.
001800 01 OTDATA-REC.
001900     03 FILLER   PIC X(38).
002000     03 GCD      PIC 9(18).
002100     03 FILLER   PIC X(01).
002200     03 ERR-FLG  PIC X(01).
002300 WORKING-STORAGE SECTION.
002400 01 INDATA-STS   PIC X(02).
002500 PROCEDURE DIVISION.
002600     OPEN INPUT INDATA OUTPUT OTDATA.
002700     PERFORM UNTIL INDATA-STS NOT = ZERO
002800       READ INDATA
002900       NOT AT END
003000         MOVE INDATA-REC TO OTDATA-REC
003100         EVALUATE TRUE
003200         WHEN M IS NOT NUMERIC
003300         WHEN N IS NOT NUMERIC
003400         WHEN M = N AND ZERO
003500           MOVE '1'  TO ERR-FLG
003600         WHEN OTHER
003700           MOVE ZERO TO ERR-FLG
003800           CALL 'GETGCD' USING BY CONTENT   M N
003900                               BY REFERENCE GCD
004000         END-EVALUATE
004100         WRITE OTDATA-REC
004200       END-READ
004300     END-PERFORM.
004400     CLOSE INDATA OTDATA.
004500     STOP RUN.
000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID. GETGCD.
000300 DATA DIVISION.
000400 WORKING-STORAGE SECTION.
000500 01 R    PIC 9(18).
000600 LINKAGE SECTION.
000700 01 M    PIC 9(18).
000800 01 N    PIC 9(18).
000900 01 GCD  PIC 9(18).
001000 PROCEDURE DIVISION USING M N GCD.
001100     PERFORM UNTIL N = ZERO
001200       COMPUTE R = FUNCTION MOD(M N)
001300       COMPUTE M = N
001400       COMPUTE N = R
001500     END-PERFORM.
001600     COMPUTE GCD = M.
001700     EXIT PROGRAM.