很好奇PTT對於CODE的P幣算法
所以獻個醜
IDENTIFICATION DIVISION.
PROGRAM-ID. PRACTICE13.
AUTHOR OSMON.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-NUM.
05WS-NUM1 PIC 9(2).
05WS-NUM2 PIC 9(2).
05WS-I PIC 9(3).
05WS-J PIC 9(3).
05WS-K PIC 9(4).
05WS-L PIC 9(4).
05WS-D PIC 9(4).
05WS-E PIC 9(2).
05WS-F PIC 9(2).
05WS-G PIC 9(2).
05WS-H PIC 9(2).
PROCEDURE DIVISION,
DISPLAY"請輸入第一個數"
ACCEPT WS-NUM1.
DISPLAY"請輸入第二個數"
ACCEPT WS-NUM2.
MOVE WS-NUM1 TO WS-E.
MOVE WS-NUM2 TO WS-F.
PERFORM 300-DIVIDE.
DISPLAY "END"
STOP RUN.
*輾轉相除法為A>B則A/B之餘數C用來B/C求餘數D循環至餘數為0為最大公因數
300-DIVIDE.
IF E NOT = F
PERFORM 400-DIVIDE
ELSE
DISPLAY WS-NUM1 "及 "WS-NUM2 " 之最大公因數為 "WS-NUM1
END-IF.
400-DIVIDE.
IF E>F THEN
DIVIDE WS-F INTO WS-E GIVING WS-D REMAINDER WS-G
PERFORM 401-DIVIDE1
ELSE
DIVIDE WS-E INTO WS-F GIVING WS-H REMAINDER WS-L
PERFORM 402-DIVIDE1
END-IF.
401-DIVIDE1.
IF WS-G NOT = 0
MOVE WS-G TO WS-E
GO TO 300-DIVIDE
ELSE
DISPLAY WS-NUM1 " 及 " WS-NUM2 " 之最大公因數為 " WS-F
DISPLAY "END"
GOBAACK.
END-IF.
402-DIVIDE1.
IF WS-L NOT = 0
MOVE WS-L TO WS-F
GO TO 300-DIVIDE
ELSE
DISPLAY WS-NUM1" 及 " WS-NUM2 " 之最大為 " WS-E
GOBACK
END-IF.