Array Dimensi 1 dan 2
Contoh : Program Array Satu Dimensi;
uses crt;
var nilai : array[1..3] of real ;
i, jumlahdata : byte ;
begin
write(’Masukan Jumlah data : ‘);readln(jumlahdata);
for i:=1 to jumlahdata do
begin
write(’Nilai ke- ‘, i ,’ : ‘);readln(nilai[i]);
end;
readln;
end.
Contoh : Program Array Dua Dimensi;
uses crt;
var matrik : array[1..3,1..2] of shortint;
i, j : byte;
begin
writeln(’Contoh Matrik :’);
matrik[1,1] := 2;
matrik[1,2] := 3;
matrik[2,1] := 3;
matrik[2,2] := 4;
matrik[3,1] := 8;
matrik[3,2] := 10;
for i:= 1 to 3 do
begin
for j:=1 to 2 do
write (matrik[i,j]:5);
writeln;
end;
readln;
end.
0 Komentar:
Posting Komentar