Home   Easy-Code    Forum  Updater 
Twitter Facebook



Program to find multiplication of two matrices using cobol

Critics Rating:

Users Rating:

* PROGRAM TO FIND MULTIPLICATION OF TWO MATRICES

************************************************

   IDENTIFICATION DIVISION.

   PROGRAM-ID.

   ENVIRONMENT DIVISION.

   DATA DIVISION.

   WORKING-STORAGE SECTION.

   01 ARRAY.

    02 X OCCURS 5 TIMES.

    03 Y OCCURS 5 TIMES.

    04 A PIC 9(2).

    04 B PIC 9(2).

    04 C PIC 9(3).

   77 M PIC 9.

   77 N PIC 9.

   77 L PIC 9.

   77 H PIC 9.

   77 I PIC 9.

   77 J PIC 9.

   77 K PIC 9.

   77 W PIC 99.

   77 E PIC Z9.

   77 P PIC ZZ9.

   PROCEDURE DIVISION.

   MAIN-PARA.

      DISPLAY " ENTER THE ORDER OF THE FIRST MATRIX ".

      ACCEPT M.

      ACCEPT N.

      COMPUTE E = M * N.

      DISPLAY " ENTER " E " NUMBERS FOR FIRST MATRIX ".

      PERFORM X-PARA VARYING I FROM 1 BY 1 UNTIL I > M

              AFTER J FROM 1 BY 1 UNTIL J > N.

      DISPLAY " ENTER THE ORDER OF THE SECOND MATRIX ".

      ACCEPT L.

      ACCEPT H.

      COMPUTE E = L * H.

      IF ( N NOT = L )

       DISPLAY " MATRIX MULTIPLICATION IS NOT POSSIBLE "

       STOP RUN.

      DISPLAY " ENTER " E " NUMBERS FOR SECOND MATRIX ".

      PERFORM Y-PARA VARYING I FROM 1 BY 1 UNTIL I > L

             AFTER J FROM 1 BY 1 UNTIL J > H.

      PERFORM K-PARA VARYING I FROM 1 BY 1 UNTIL I > M

             AFTER J FROM 1 BY 1 UNTIL J > H.

      DISPLAY ( 1 , 1 ) ERASE.

      DISPLAY " THE GIVEN MATRICES ARE ".

      MOVE 2 TO LIN.

      MOVE 0 TO COL.

      PERFORM M1-PARA VARYING I FROM 1 BY 1 UNTIL I > M

             AFTER J FROM 1 BY 1 UNTIL J > N.

      MOVE 2 TO LIN.

      MOVE 15 TO COL.

      PERFORM M2-PARA VARYING I FROM 1 BY 1 UNTIL I > L

             AFTER J FROM 1 BY 1 UNTIL J > H.

      COMPUTE W = M + H.

      MOVE W TO LIN.

      DISPLAY ( LIN + 1 , 1 ) " THE PRODUCT OF THE TWO MATRICES IS ".

      COMPUTE W = W + 2.

      MOVE W TO LIN.

      MOVE 0 TO COL.

      PERFORM D-PARA VARYING I FROM 1 BY 1 UNTIL I > M

             AFTER J FROM 1 BY 1 UNTIL J > H.

      STOP RUN.

   X-PARA.

      ACCEPT A( I , J ).

   Y-PARA.

      ACCEPT B( I , J ).

   K-PARA.

      MOVE 0 TO C( I , J ).

      PERFORM C-PARA VARYING K FROM 1 BY 1 UNTIL K > L.

   C-PARA.

      COMPUTE C( I , J ) = C(I , J) + A(I , K) * B(K , J).

   M1-PARA.

      COMPUTE COL = COL + 3.

      MOVE A( I , J ) TO P.

      DISPLAY ( LIN , COL ) P.

      IF ( J = N )

       COMPUTE LIN = LIN + 1

       MOVE 0 TO COL.

   M2-PARA.

      COMPUTE COL = COL + 3.

      MOVE B( I , J ) TO P.

      DISPLAY ( LIN , COL ) P.

      IF ( J = H )

       COMPUTE LIN = LIN + 1

       MOVE 15 TO COL.

   D-PARA.

      COMPUTE COL = COL + 3.

      MOVE C( I , J ) TO P.

      DISPLAY ( LIN , COL ) P.

      IF ( J = H )

       COMPUTE LIN = LIN + 1

       MOVE 0 TO COL.

Courtesy, Source, References & Regards: Kishore AVGK

While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright@2009-2011 by KuGuNi.com. All Rights Reserved.