早教吧 育儿知识 作业答案 考试题库 百科 知识分享

COBOL到底能不能做出计算器来?源码:IDENTIFICATIONDIVISION.PROGRAM-ID.LYX12.ENVIRONMENTDIVISION.DATADIVISION.WORKING-STORAGESECTION.77KPIC9(9).77OPIC9(9).77APIC9(9).PROCEDUREDIVISION.DISPLAY"ENTERTHESTEP".ACCEPTO.ACCEPT

题目详情
COBOL到底能不能做出计算器来?
源码:IDENTIFICATION DIVISION.
PROGRAM-ID.LYX12.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 K PIC 9(9).
77 O PIC 9(9).
77 A PIC 9(9).
PROCEDURE DIVISION.
DISPLAY "ENTER THE STEP".
ACCEPT O.
ACCEPT K.
COMPUTE A = K + O.
DISPLAY "THE MAXMIUM OF Y IS ",A.
STOP RUN.
如果O传入的是11,K传入的是12的话A的结果是+230000000而其实想要的结果只是23
▼优质解答
答案和解析
IDENTIFICATION DIVISION.
PROGRAM-ID. LYX12.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 K PIC X(9).
77 O PIC X(9).
77 A PIC 9.
77 B PIC 9.
77 C PIC 9(9).
77 D PIC 9(9).
77 E PIC Z(9).
PROCEDURE DIVISION.
DISPLAY "ENTER THE STEP".
ACCEPT O.
ACCEPT K.
INSPECT O TALLYING A FOR ALL " ".
COMPUTE A = 9 - A.
MOVE O(1:A) TO C.
INSPECT K TALLYING B FOR ALL " ".
COMPUTE B = 9 - B.
MOVE K(1:B) TO D.
COMPUTE E = C + D.
DISPLAY "THE MAXMIUM OF Y IS ", E.
STOP RUN.
看了 COBOL到底能不能做出计算...的网友还看了以下: