1. CONTOH PROGRAM array 1 dimensi
Program coba_array;
Uses wincrt;
Var
i,jum_data:integer;
nama:array [1..20] of string;
Begin
writeln(‘MENCETAK NAMA MAHASISWA DENGAN ARRAY’);
writeln;
write(‘masukkan jumlah data : ‘);readln(jum_data);
for i:=1 to jum_data do
Begin
write(‘masukkan nama ke ‘,i,’ : ‘);readln(nama[i]);
end;
writeln;
writeln(‘No Nama’);
writeln(‘———————-‘);
for i:=1 to jum_data do
writeln(i:5,nama[i]:15);
End.
Uses wincrt;
Var
i,jum_data:integer;
nama:array [1..20] of string;
Begin
writeln(‘MENCETAK NAMA MAHASISWA DENGAN ARRAY’);
writeln;
write(‘masukkan jumlah data : ‘);readln(jum_data);
for i:=1 to jum_data do
Begin
write(‘masukkan nama ke ‘,i,’ : ‘);readln(nama[i]);
end;
writeln;
writeln(‘No Nama’);
writeln(‘———————-‘);
for i:=1 to jum_data do
writeln(i:5,nama[i]:15);
End.
2. CONTOH PROGRAM array 2 dimensi
Program coba_array2_dimensi;
Uses wincrt;
const maks=3;
Var
i,j:integer;
matriks:array [1..maks,1..maks] of integer;
Begin
writeln(‘MENGISI MATRIKS A’);
writeln;
for i:=1 to maks do
for j:=1 to maks do begin
write(‘A [‘,i,’,’,j,’] : ‘);readln(matriks[i,j]);
end;writeln;
writeln(‘ISI MATRIKS A’);
writeln(‘————-‘);
for i:=1 to maks do
for j:=1 to maks do begin
if j=maks then writeln(matriks[i,j])
Else write(matriks[i,j],’ ‘);
end;
End.
Uses wincrt;
const maks=3;
Var
i,j:integer;
matriks:array [1..maks,1..maks] of integer;
Begin
writeln(‘MENGISI MATRIKS A’);
writeln;
for i:=1 to maks do
for j:=1 to maks do begin
write(‘A [‘,i,’,’,j,’] : ‘);readln(matriks[i,j]);
end;writeln;
writeln(‘ISI MATRIKS A’);
writeln(‘————-‘);
for i:=1 to maks do
for j:=1 to maks do begin
if j=maks then writeln(matriks[i,j])
Else write(matriks[i,j],’ ‘);
end;
End.
Tidak ada komentar:
Posting Komentar