Home   Easy-Code    Forum  Updater 
Twitter Facebook



Program to find the row sum and column sum of a matrix using cobol

Critics Rating:

Users Rating:

* PROGRAM TO FIND THE ROW SUM AND COLUMN SUM OF A MATRIX

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

   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).

   77 M PIC 9.

   77 N PIC 9.

   77 I PIC 9.

   77 J PIC 9.

   77 E PIC 9(2).

   77 S PIC 9(3) VALUE 0.

   77 P PIC ZZ9.

   PROCEDURE DIVISION.

   MAIN-PARA.

      DISPLAY " ENTER THE ORDER OF A MATRIX ".

      ACCEPT M.

      ACCEPT N.

      COMPUTE E = M * N.

      DISPLAY " ENTER " E " NUMBERS ".

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

              AFTER J FROM 1 BY 1 UNTIL J > N.

      MOVE 2 TO COL.

      PERFORM Y-PARA VARYING I FROM 1 BY 1 UNTIL I > M.

      PERFORM Z-PARA VARYING I FROM 1 BY 1 UNTIL I > M.

      STOP RUN.

   X-PARA.

      ACCEPT A( I , J ).

   Y-PARA.

      PERFORM D-PARA VARYING J FROM 1 BY 1 UNTIL J > N.

      MOVE S TO P.

      DISPLAY " THE SUM OF " I " ROW " P.

      MOVE 0 TO S.

   D-PARA.

      COMPUTE S = S + A( I , J ).

   Z-PARA.

      PERFORM E-PARA VARYING J FROM 1 BY 1 UNTIL J > N.

      MOVE S TO P.

      DISPLAY " THE SUM OF " I " COLUMN " P.

      MOVE 0 TO S.

   E-PARA.

      COMPUTE S = S + A( J , I ).

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.