IDENTIFICATION DIVISION.
PROGRAM-ID MAT-ADD.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 MAT1.
02 MR1 OCCURS 5 TIMES.
03 MC1 PIC 9(2) OCCURS 5 TIMES.
01 MAT2.
02 MR2 OCCURS 5 TIMES.
03 MC2 PIC 9(2) OCCURS 5 TIMES.
01 MAT3.
02 MR3 OCCURS 5 TIMES.
03 MC3 PIC ZZZ(9) OCCURS 5 TIMES.
77 ROW1 PIC 9.
77 ROW2 PIC 9.
77 COL1 PIC 9.
77 COL2 PIC 9.
77 I PIC 9.
77 J PIC 9.
PROCEDURE DIVISION.
MAIN-PARA.
DISPLAY 'MATRIX ADDITION'.
DISPLAY ' '.
DISPLAY 'ENTER THE NUMBER OF ROW AND COLUMNS OF 1 MATRIX'.
ACCEPT ROW1.
ACCEPT COL1.
DISPLAY 'ENTER THE NUMBER OF ROW AND COLUMNS OF 2ND MATRIX'.
ACCEPT ROW2.
ACCEPT COL2.
IF(ROW IS NOT EQUALS TO ROW2) OR (COL1 NOT EQUALS TO COL2)
DISPLAY 'MATRIX ADDITION IS NOT POSSIBLE'
ELSE
PERFORM COMPU-PARA
STOP RUN.
COMPU-PARA.
DISPLAY 'ENTER THE ELEMENTS OF MATRIX'.
PERFORM ACCPARA1 VARYING I FROM 1 BY 1 UNTIL I > ROW1
AFTER J FROM 1 BY 1 UNTIL J > COL1.
DISPLAY 'ENTER THE ELEMENTS OF MATRIX2'.
PERFORM ACCPARA2 VARYING I FROM 1 BY 1 UNTIL I > ROW2
AFTER J FROM 1 BY 1 UNTIL J > COL2.
PERFORM ADDMAT-PARA VARYING I FROM 1 BY 1 UNTIL I > ROW1
AFTER J FROM 1 BY 1 UNTIL J > COL1.
DISPLAY ( 1 1 ) ERASE.
MOVE 3 TO LIN.
MOVE 10 TO COL.
DISPALY ' '.
DISPLAY ' THE FIRST MATRIX IS'.
DISPLAY ' '.
PERFORM DISP1-PARA VARYING I FROM 1 BY 1 UNTIL I > ROW1
AFTER J FROM 1 BY 1UNTIL J > COL1.
DISPLAY ' '.
MOVE 10 TO LIN.
MOVE 10 TO COL.
DISPLAY ' '.
DISPLAY 'THE SECOND MATRIX IS'.
DISPLAY ' '.
PERFORM DISP2-PARA VARYING I FROM 1 BY 1 UNTIL I > ROW12
AFTER J FROM 1 BY 1UNTIL J > COL1.
DISPLAY ' '.
MOVE 17 TO LIN.
MOVE 10 TO COL.
DISPLAY ' '.
DISPLAY 'THE RESULTANT MATRIX IS'.
DISPLAY ' '.
PERFORM DISP-PARA VARYING I FROM 1 BY 1 UNTIL I > ROW 1
AFTER J FROM 1 BY 1UNTIL J > COL1.
DISPLAY ' '.
ACCPARA1.
ACCEPT MC1 (I J).
ACCPARA2.
ACCEPT MC2 (I J).
ADDMAT-PARA
COMPUTE MC3 (I J) = MC1 (J I) + MC2 (I J).
DISP-PARA
DISPLAY (LIN . COL ) MC3 (I J).
ADD 5 TO COL.
IF J IS EQUAL TO COL
ADD 1 TO LIN MOVE 10 TO COL.
DISP1-PARA
DISPLAY (LIN , COL ) MC1 (I J).
ADD 5 TO COL.
IF J IS EQUAL TO COL.
ADD 1 TO LIN MOVE 10 TO COL
DISP2-PARA.
DISPLAY ( LIN, COL) MC1 (I J).
ADD 5 TO COL.
IF J IS EQUAL TO COL.
ADD 1 TO LIN MOVE 10 TO COL
output:
enter the number of rows for 1 matrix:
2*2
enter the number of rows for 2 matrix:
2*2
enter the elements of 1 matrix:
1 2
3 4
the first matrix is
1 2
3 4
enter the second matrix:
3 4
6 7
the second matrix is:
3 4
6 7
the resultant matrix is:
4 6
9 11
PROGRAM-ID MAT-ADD.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 MAT1.
02 MR1 OCCURS 5 TIMES.
03 MC1 PIC 9(2) OCCURS 5 TIMES.
01 MAT2.
02 MR2 OCCURS 5 TIMES.
03 MC2 PIC 9(2) OCCURS 5 TIMES.
01 MAT3.
02 MR3 OCCURS 5 TIMES.
03 MC3 PIC ZZZ(9) OCCURS 5 TIMES.
77 ROW1 PIC 9.
77 ROW2 PIC 9.
77 COL1 PIC 9.
77 COL2 PIC 9.
77 I PIC 9.
77 J PIC 9.
PROCEDURE DIVISION.
MAIN-PARA.
DISPLAY 'MATRIX ADDITION'.
DISPLAY ' '.
DISPLAY 'ENTER THE NUMBER OF ROW AND COLUMNS OF 1 MATRIX'.
ACCEPT ROW1.
ACCEPT COL1.
DISPLAY 'ENTER THE NUMBER OF ROW AND COLUMNS OF 2ND MATRIX'.
ACCEPT ROW2.
ACCEPT COL2.
IF(ROW IS NOT EQUALS TO ROW2) OR (COL1 NOT EQUALS TO COL2)
DISPLAY 'MATRIX ADDITION IS NOT POSSIBLE'
ELSE
PERFORM COMPU-PARA
STOP RUN.
COMPU-PARA.
DISPLAY 'ENTER THE ELEMENTS OF MATRIX'.
PERFORM ACCPARA1 VARYING I FROM 1 BY 1 UNTIL I > ROW1
AFTER J FROM 1 BY 1 UNTIL J > COL1.
DISPLAY 'ENTER THE ELEMENTS OF MATRIX2'.
PERFORM ACCPARA2 VARYING I FROM 1 BY 1 UNTIL I > ROW2
AFTER J FROM 1 BY 1 UNTIL J > COL2.
PERFORM ADDMAT-PARA VARYING I FROM 1 BY 1 UNTIL I > ROW1
AFTER J FROM 1 BY 1 UNTIL J > COL1.
DISPLAY ( 1 1 ) ERASE.
MOVE 3 TO LIN.
MOVE 10 TO COL.
DISPALY ' '.
DISPLAY ' THE FIRST MATRIX IS'.
DISPLAY ' '.
PERFORM DISP1-PARA VARYING I FROM 1 BY 1 UNTIL I > ROW1
AFTER J FROM 1 BY 1UNTIL J > COL1.
DISPLAY ' '.
MOVE 10 TO LIN.
MOVE 10 TO COL.
DISPLAY ' '.
DISPLAY 'THE SECOND MATRIX IS'.
DISPLAY ' '.
PERFORM DISP2-PARA VARYING I FROM 1 BY 1 UNTIL I > ROW12
AFTER J FROM 1 BY 1UNTIL J > COL1.
DISPLAY ' '.
MOVE 17 TO LIN.
MOVE 10 TO COL.
DISPLAY ' '.
DISPLAY 'THE RESULTANT MATRIX IS'.
DISPLAY ' '.
PERFORM DISP-PARA VARYING I FROM 1 BY 1 UNTIL I > ROW 1
AFTER J FROM 1 BY 1UNTIL J > COL1.
DISPLAY ' '.
ACCPARA1.
ACCEPT MC1 (I J).
ACCPARA2.
ACCEPT MC2 (I J).
ADDMAT-PARA
COMPUTE MC3 (I J) = MC1 (J I) + MC2 (I J).
DISP-PARA
DISPLAY (LIN . COL ) MC3 (I J).
ADD 5 TO COL.
IF J IS EQUAL TO COL
ADD 1 TO LIN MOVE 10 TO COL.
DISP1-PARA
DISPLAY (LIN , COL ) MC1 (I J).
ADD 5 TO COL.
IF J IS EQUAL TO COL.
ADD 1 TO LIN MOVE 10 TO COL
DISP2-PARA.
DISPLAY ( LIN, COL) MC1 (I J).
ADD 5 TO COL.
IF J IS EQUAL TO COL.
ADD 1 TO LIN MOVE 10 TO COL
output:
enter the number of rows for 1 matrix:
2*2
enter the number of rows for 2 matrix:
2*2
enter the elements of 1 matrix:
1 2
3 4
the first matrix is
1 2
3 4
enter the second matrix:
3 4
6 7
the second matrix is:
3 4
6 7
the resultant matrix is:
4 6
9 11