Jumat, 26 November 2010

Listing Matrik Cobol

IDENTIFICATION DIVISION.
       PROGRAM-ID. MATRIX-DIMENSI.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       77 I PIC 99.
       77 J PIC 99.
       01 MASUKAN.
           02 MATRIK OCCURS 2 TIMES.
               03 MAT1 OCCURS 2 TIMES PIC S9(3).
               03 MAT2 OCCURS 2 TIMES PIC S9(3).
               03 MAT-HASIL OCCURS 2 TIMES PIC -ZZ9.

       SCREEN SECTION.
       01 HAPUS.
           02 BLANK SCREEN.
       PROCEDURE DIVISION.
       MULAI.
           DISPLAY HAPUS.
           MOVE 1 TO LIN.
           DISPLAY(LIN, 1) 'MATRIK A : '.
           ADD 1 TO LIN.
           PERFORM DATA1 VARYING I
               FROM 1 BY 1 UNTIL I > 2
                   AFTER J FROM 1 BY 1 UNTIL J > 2.
           MOVE 1 TO LIN.
           DISPLAY (LIN, 30) 'MATRIK B : '.
           ADD 1 TO LIN.
           DISPLAY SPACE.

           PERFORM DATA2 VARYING I
               FROM 1 BY 1 UNTIL I > 2
                   AFTER J FROM 1 BY 1 UNTIL J > 2.
           DISPLAY SPACE.
           ADD 1 TO LIN.
           DISPLAY (LIN, 10) 'MATRIK A + MATRIK B'.
           DISPLAY (LIN, 40) 'MATRIK A - MATRIK B'.
           ADD 2 TO LIN.
           MOVE 10 TO COL.

           PERFORM JUMLAH VARYING I
               FROM 1 BY 1 UNTIL I > 1
                   AFTER J FROM 1 BY 1 UNTIL J > 1.
           MOVE 10 TO COL.
           PERFORM JUMLAH VARYING I
               FROM 1 BY 1 UNTIL I > 2
                   AFTER J FROM 1 BY 1 UNTIL J > 2.
           MOVE 40 TO COL.
           PERFORM KURANG VARYING I
               FROM 1 BY 1 UNTIL I > 1
                   AFTER J FROM 1 BY 1 UNTIL J > 1.
           MOVE 40 TO COL.
           PERFORM KURANG VARYING I
               FROM 1 BY 1 UNTIL I > 2
                   AFTER J FROM 1 BY 1 UNTIL J > 2.
       SELESAI.
           STOP RUN.
       DATA1.
           DISPLAY( LIN, 1 ) '[ ', I , ',' , J , '] = '.
           ACCEPT ( , ) MAT1( I , J ).
           ADD 1 TO LIN.
       DATA2.
           DISPLAY( LIN, 30 ) '[ ', I , ',' , J , '] = '.
           ACCEPT ( , ) MAT2( I , J ).
           ADD 1 TO LIN.
       JUMLAH.
           COMPUTE MAT-HASIL( I , J )=MAT1( I , J ) + MAT2( I , J ).
           IF J = 1 DISPLAY( 10 , COL ) MAT-HASIL( I, J ).
           IF J = 2 SUBTRACT 7 FROM COL.
           IF J = 2 DISPLAY( 13 , COL ) MAT-HASIL( I, J ).
           ADD 7 TO COL.
       KURANG.
           COMPUTE MAT-HASIL( I , J )=MAT1( I , J ) - MAT2( I , J >.
           IF J = 1 DISPLAY( 10 , COL ) MAT-HASIL( I, J ).
           IF J = 2 SUBTRACT 7 FROM COL.
           IF J = 2 DISPLAY( 13 , COL ) MAT-HASIL( I, J ).
           ADD 7 TO COL.

Tidak ada komentar:

Posting Komentar