写一个COBOL程序,展示算术运算语法

2024-12-18 00:39:59
推荐回答(1个)
回答1:

IDENTIFICATION DIVISION.
PROGRAM-ID COMPUTE-TEST.
AUTHER XXX.
*
ENIRONMENT DIVISION.
*
DATA DIVISION.
WORKING-STORAGE SECTION.
01 NUM1 PIC 9.
01 NUM2 PIC 9.
01 NUM3 PIC 9.
01 RESULT PIC 9.
*
PROCEDUTR DIVISION.
MOVE 3 TO NUM1.
MOVE 2 TO NUM2.
MOVE 5 TO NUM3.
*
COMPUTE RESULT = NUM2 +NUM3.
END-COMPUTE.
DISPLAY "RESULT-1:",RESULT.
*
COMPUTE RESULT = (NUM3 - NUM1) * NUM2.
END-COMPUTE.
DISPLAY "RESULT-2:",RESULT.
*
COMPUTE RESULT = NUM1 ** NUM2 + NUM3 * 2.
END-COMPUTE.
DISPLAY "RESULT-3:",RESULT.
*
COMPUTE RESULT = (1 + 2) * 3 - 4.
END-COMPUTE.
DISPLAY "RESULT-4:",RESULT.
*
COMPUTE RESULT = NUM1 + (3 + 2 - NUM3) * NUM2 / 5 - 2.
END-COMPUTE.
DISPLAY "RESULT-5:",RESULT.
STOP RUN.