0% found this document useful (0 votes)
34 views8 pages

Array Dua Dimensi

The document discusses two-dimensional arrays in Pascal, including how they can represent tables or matrices with indices for rows and columns, examples of declaring and initializing 2D arrays, and an example of adding two matrices by iterating through and summing the elements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views8 pages

Array Dua Dimensi

The document discusses two-dimensional arrays in Pascal, including how they can represent tables or matrices with indices for rows and columns, examples of declaring and initializing 2D arrays, and an example of adding two matrices by iterating through and summing the elements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 8

Array Dua Dimensi

Di dalam pascal Array dapat berdimensi lebih dari satu


yang disebut dengan array dimensi banyak
(Multidimensional array).

Array 2 dimensi dapat mewakili suatu bentuk tabel


atau matrik, yaitu indeks pertama menunjukkan baris
dan indeks ke dua menunjukkan kolom dari tabel atau
matrik.
Contoh Bentuk Tampilan
Let us have the 2 dimensional array defined first. Think of a
grid where each box is located by using horizontal and vertical
coordinates just in the example below:

1 2 3 4 5

2        

3     3,4  

4        

5   5,3    

An example of a 5 by 5 2D array illustrated on a grid


Having the vertical axis as the 1st dimension and the horizontal one as the 2nd
dimension, the above example is illustrated as follows:

Var
my2DArray : Array[1..3][1..5] of Byte;
Begin
my2DArray[2][4] := 10;
End.

1 2 3 4 5

2     10  

3        
Program Deklarasi_Array_Dua_Dimensi;
Uses Wincrt; Contoh 2.1
Var
Tabel : Array [1..3, 1..2] of Integer;
i,j : Integer;
Begin
ClrScr;
Tabel [1,1] :=1;
Tabel [1,2] :=2;
Tabel [2,1] :=3;
Tabel [2,2] :=4;
Tabel [3,1] :=5;
Tabel [3,2] :=6;
For I := 1 to 3 Do
Begin
For J:= 1 to 2 Do
Begin
Writeln ('Elemen ',i,',',j ,'= ',tabel [i,j] );
End;
End;
End.
Program penjumlahan_matrik; Contoh 2.2
Uses Wincrt;
Var
Matrik1,Matrik2, Hasil : Array[1..3,1..2] of Integer;
i,j : Integer;
Begin
ClrScr;
{ input matrik ke satu }
Writeln(' Elemen matrik satu');
For i := 1 to 3 Do
Begin
For j := 1 to 2 Do
Begin
Write('Elemen baris -',i,' Kolom -',j,'= ');
Readln(matrik1 [i,j]);
End;
End;
Contoh 2.2 cont…
{input matrik ke dua}
Writeln('input elemen matrik dua');
For i:= 1 to 3 Do
Begin
For j:= 1 to 2 Do
Begin
Write('Elemen baris -',i,' kolom -',j,'= ');
Readln(matrik2 [i,j]);
End;
End;
Contoh 2.2 cont…
{proses penjumlahan tiap elemen}
For i := 1 to 3 Do
Begin
For j:= 1 to 2 Do
Begin
Hasil[i,j] :=Matrik1 [i,j]+Matrik2[i,j];
End;
End;
Contoh 2.2 cont…
{proses cetak hasil}
For i:= 1 to 3 Do
Begin
For j:= 1 to 2 Do
Begin
Write(Hasil[i,j] :6);
End;
Writeln;
End;
Readln;
End.

You might also like