Write a COBOL program to MULTIPLY TWO MATRICES.


       IDENTIFICATION DIVISION.
       PROGRAM-ID. MATRIX-MULTIPLICATION.
       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  K       PIC 99.
       01  RW      PIC 99.
       01  RC      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) " I-Matirx : Rows : ".
           DISPLAY (03 31) "Columns : ".
           ACCEPT (03 28) RW.
           ACCEPT (03 41) RC.
           DISPLAY (04 10) "II-Matirx : Rows : ".
           DISPLAY (04 31) "Columns : ".
           DISPLAY (04 28) RC.
           ACCEPT (04 41) CL.
           
           DISPLAY (06 10) "Enter the elements of:".
           DISPLAY (07 10) "First Matrix ".
           DISPLAY (07 50) "Second Matrix".
           MOVE 09 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 > RC.
           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) "Multiplication 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 > RC.
           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.
           MOVE 0 TO C(I J).
           PERFORM MULTI-PARA VARYING K FROM 1 BY 1 UNTIL K > RC.
       MULTI-PARA.
           COMPUTE C(I J) = C(I J) + A(I K) * B(K 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.

4 comments:

  1. This is wonderful and quite informative blog I have learnt so many things from here.
    famous design firms

    ReplyDelete
  2. An excellent company is an initial step in getting your business one stage further through portraying the spot-on visible message to your clients.
    best company logos

    ReplyDelete
  3. very good and very usefull blog.

    ReplyDelete
  4. It was well worth the investment in terms of both the quality and the speed of the work
    top web design firm

    ReplyDelete