Contoh Program Matriks Pada COBOL
DENTIFICATION DIVISION.
PROGRAM-ID. MATRIK.
AUTHOR. NURFITRIANA.
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 9.
03 MAT2 OCCURS 2 TIMES PIC 9.
03 MAT-HASIL OCCURS 2 TIMES PIC ZZZ.
SCREEN SECTION.
01 HAPUS-LAYAR.
02 BLANK SCREEN.
PROCEDURE DIVISION.
MULAI.
DISPLAY HAPUS-LAYAR.
MOVE 2 TO LIN.
DISPLAY(LIN, 1) 'MATRIK PERTAMA'.
ADD 1 TO LIN.
PERFORM MATRIK1 VARYING I
FROM 1 BY I UNTIL I > 2
AFTER J FROM 1 BY 1 UNTIL J > 2.
MOVE 1 TO LIN.
DISPLAY(LIN, 30) 'MATRIK KEDUA'.
ADD 1 TO LIN.
PERFORM MATRIK2 VARYING I
FROM 1 BY 1 UNTIL I > 2
AFTER J FROM 1 BY 1 UNTIL J > 2.
MOVE 1 TO LIN.
DISPLAY (10, 10) 'PENJUMLAHAN MATRIK'.
DISPLAY SPACE.
MOVE 13 TO COL.
PERFORM HITUNG-NILAI VARYING I
FROM 1 BY 1 UNTIL I > 1
AFTER J FROM 1 BY 1 UNTIL J > 1.
MOVE 13 TO COL.
PERFORM HITUNG-NILAI VARYING I
FROM 1 BY 1 UNTIL I > 2
AFTER J FROM 1 BY 1 UNTIL J > 2.
STOP RUN.
MATRIK1.
DISPLAY(LIN, 1) 'NILAI[', I , ',' , J , ']:'.
ACCEPT ( , ) MAT1(I, J).
ADD 1 TO LIN.
MATRIK2.
DISPLAY(LIN, 30) 'NILAI[', I , ',' , J , ']:'.
ACCEPT ( , ) MAT2(I, J).
ADD 1 TO LIN.
HITUNG-NILAI.
COMPUTE MAT-HASIL(I, J) = MAT1(I, J) + MAT2(I, J).
DISPLAY ( , COL) MAT-HASIL(I, J).
ADD 7 TO COL.
Posting Komentar