Senin, 25 Oktober 2010

Program Tab

,
program Tab2dim;
(* File : Tab2dim.pas *)
(* Tabel integer dua dimensi (matriks) *)
(* Kamus *)

type
(* Cara I : sebagai array dua dimensi *)
MatInt = array [1..3, 1..3] of integer;
(* Cara 2 : sebagai array of array *)
MatArr = array [1..3] of array [1..3] of integer;

var
M1 : MatInt;
MA1 : MatArr;
i , j : Integer ;

(* Algoritma *)
begin
writeln (' Array dua dimensi : ');
(* Mengisi Matrik dua dimensi *)
for i := 1 to 3 do
begin
for j := 1 to 3 do

begin
M1 [i,j] := i * j;
end; (* for j *)
end;
(* Menulis hasil isian di atas *)
for i := 1 to 3 do
begin
for j:= 1 to 3 do
begin
write (' (i, j) = ', i, ',', j, ' => M1 [i, j] = ', M1 [i, j]);
end;
writeln;
end;
writeln ( ' Array of array : ');
(* Mengisi array of array : perhatikan cara mengacu elemen *)
for i := 1 to 3 do
begin
for j := 1 to 3 do
begin
MA1 [i] [j] := i*j;
end;
end;
(* Menulis hasil isian di atas *)
for i := 1 to 3 do
begin
for j := 1 to 3 do
begin
(* Cobalah dua instruksi write sbb *)
(* write (' (i,j) = ', i, ', ', j, ' => MA1 [i,j] = ',MA1 [i,j] ); *)
write ('(i,j) = ', i, ', ', j, ', => MA1 [i,j] = ',MA1 [i][j] );
end;
writeln;
end;
end.


================================================================
program Tab3dim;
(* File : Tab3dim.pas *)
(* Tabel integer tiga dimensi *)
(* Kamus *)

type
(* Cara I : sebagai array tiga dimensi *)
MatInt = array [1..2, 1..2, 1..2] of integer;
(* Cara 2 : sebagai array of array of array *)
MatArr = array [1..2] of array [1..2] of array [1..2] of integer;

var
M1: MatInt;
MA1: MatArr;
i,j,k : Integer;
(* Algoritma *)

begin
writeln (' Array tiga dimensi : ');
(* Mengisi Matriks tiga dimensi *)
for i := 1 to 2 do
begin
for j := 1 to 2 do
begin
for k := 1 to 2 do
M1 [i,j,k] := i*j;
end;
end;

(* Menulis hasil isian di atas *)
for i := 1 to 2 do
begin
for i := 1 to 2 do
begin
for k := 1 to 2 do
writeln ('(i,j,k) = ', i, ', ', k, ' => M1 [i,j,k] = ', M1 [i,j,k]);
end;
end;
writeln ( 'Array of array of array : ' );
(* Mengisikan array of array : perhatikan cara mengacu elemen *)
for i := 1 to 2 do
begin
for j := 1 to 2 do
begin
for k := 1 to 2 do
begin MA1 [i] [j] [k] := i*j; end;
end;
end;
(* Menulis hasil isian di atas *)
for i := 1 to 2 do
begin
for j := 1 to 2 do
begin
for k := 1 to 2 do
begin
writeln('(i,j,k =', i, ',', j,',',k,', =>MA1[i,j,k]=' MA1[i][j][k]);
end;
end;
end;
end.


0 komentar to “Program Tab”

Posting Komentar