IDENTIFICATION DIVISION. PROGRAM-ID. MATRIX-ADDITION. ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. OBJECT-COMPUTER. DATA DIVISION. WORKING-STORAGE SECTION. 01 MATRIXA. 02 MATA OCCURS 10 TIMES. 03 A PIC S9(3) OCCURS 10 TIMES. 01 MATRIXB. 02 MATB OCCURS 10 TIMES. 03 B PIC S9(3) OCCURS 10 TIMES. 01 MATRIXC. 02 MATC OCCURS 10 TIMES. 03 C PIC S9(3) OCCURS 10 TIMES. 01 E-VAL PIC -ZZ9. 01 I PIC 99. 01 J PIC 99. 01 RW PIC 99. 01 CL PIC 99. PROCEDURE DIVISION. MAIN-PARA. DISPLAY (01 01) ERASE. DISPLAY (02 10) "Enter the Order of the Matices". DISPLAY (03 10) "Rows : ". DISPLAY (03 20) "Columns : ". ACCEPT (03 17) RW. ACCEPT (03 30) CL. DISPLAY (05 10) "Enter the elements of:". DISPLAY (06 10) "First Matrix ". DISPLAY (06 50) "Second Matrix". MOVE 08 TO LIN. MOVE 10 TO COL. PERFORM READ-A1 VARYING I FROM 1 BY 1 UNTIL I > RW. MOVE 08 TO LIN. MOVE 50 TO COL. PERFORM READ-B1 VARYING I FROM 1 BY 1 UNTIL I > RW. PERFORM COMPUTE-PARA VARYING I FROM 1 BY 1 UNTIL I > RW AFTER J FROM 1 BY 1 UNTIL J > CL. ADD 2 TO LIN. MOVE 10 TO COL. DISPLAY (LIN, 10) "Sum of the Matrices". DISPLAY (LIN + 1, 10) "-------------------". ADD 2 TO LIN. PERFORM DISP-C1 VARYING I FROM 1 BY 1 UNTIL I > RW. DISPLAY (LIN, 10) "===================". STOP RUN. READ-A1. PERFORM READ-A VARYING J FROM 1 BY 1 UNTIL J > CL. ADD 1 TO LIN. MOVE 10 TO COL. READ-A. ACCEPT (LIN, COL) A(I J). ADD 5 TO COL. READ-B1. PERFORM READ-B VARYING J FROM 1 BY 1 UNTIL J > CL. ADD 1 TO LIN. MOVE 50 TO COL. READ-B. ACCEPT (LIN, COL) B(I J). ADD 5 TO COL. COMPUTE-PARA. COMPUTE C(I J) = A(I J) + B(I J). DISP-C1. PERFORM DISP-C VARYING J FROM 1 BY 1 UNTIL J > CL. ADD 1 TO LIN. MOVE 10 TO COL. DISP-C. MOVE C(I J) TO E-VAL. DISPLAY (LIN, COL) E-VAL. ADD 5 TO COL.
Write a COBOL program to ADD TWO MATRICES.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment