Sahabat-sahabatku jangan pantang menyerah untuk tetap belajar :) Ini ada contoh program lagi dengan array dimensi dua pada pascal. Selamat menyimak :) :) :)
program arrayd2;
uses crt;
type larik=array[1..5,1..6] of byte;
const prodi:array[1..5] of string=('KIMIA','MESIN','INDUSTRI','ELEKTRO','INFORMATIKA');
var mhs:larik;
i,j:byte;
max,min:byte;
prodimax,prodimin:string;
thmax,thmin:word;
jumbar,jumkol:integer;
begin
{mengisi}
for i:=1 to 5 do
begin
for j:=1 to 6 do
begin
write('mengisi data prodi ',prodi[i],' th ',2006+j,' = ');readln(mhs[i,j]);
end;
writeln;
end;
{tampilkan}
clrscr;
writeln('________________________________________________________________________');
writeln('| Prodi | 2006 | 2007 | 2008 | 2009 | 2010 | 2011 | 2012 | Total |');
writeln('|-----------|------|------|------|------|------|------|------|---------|');
for i:=1 to 5 do
begin
write('|',prodi[i]:11);
for j:=1 to 7 do
begin
write('| ',mhs[i,j]:3,' ');
jumbar:=jumbar+mhs[i,j];
end;
write('| ',jumbar:5,' |');
jumbar:=0;
writeln;
end;
writeln('|-----------|------|------|------|------|------|------|------|---------|');
write('| Total |');
for j:=1 to 7 do
begin
for i:=1 to 5 do
begin
jumkol:=jumkol+mhs[i,j];
end;
write(' ',jumkol:4,' |');
jumkol:=0;
end;
writeln('/////////|');
writeln('|___________|______|______|______|______|______|______|______|_________|');
readln;
writeln('Prodi dengan mahasiswa <50 orang adalah');
for i:=1 to 5 do
begin
for j:=1 to 6 do
if mhs[i,j]<50 then
writeln('prodi ',prodi[i],' tahun ',2006+j,' sebanyak ',mhs[i,j],' orang');
end;
max:=0;
min:=255;
for i:=1 to 5 do
begin
for j:=1 to 6 do
begin
if mhs[i,j]> max then
begin
max:=mhs[i,j];thmax:=2006+j;prodimax:=prodi[i];end;
if mhs[i,j]< min then
begin
min:=mhs[i,j];thmin:=2006+j;prodimin:=prodi[i];end;
end;
end;
{tampilkan}
writeln;
writeln('mahasiswa terbanyak dari prodi ',prodimax,' th ',thmax,' sebanyak ',max);
writeln('mahasiswa tersedikit dari prodi ',prodimin,' th ',thmin,' sebanyak ',min);
end.
program arrayd2;
uses crt;
type larik=array[1..5,1..6] of byte;
const prodi:array[1..5] of string=('KIMIA','MESIN','INDUSTRI','ELEKTRO','INFORMATIKA');
var mhs:larik;
i,j:byte;
max,min:byte;
prodimax,prodimin:string;
thmax,thmin:word;
jumbar,jumkol:integer;
begin
{mengisi}
for i:=1 to 5 do
begin
for j:=1 to 6 do
begin
write('mengisi data prodi ',prodi[i],' th ',2006+j,' = ');readln(mhs[i,j]);
end;
writeln;
end;
{tampilkan}
clrscr;
writeln('________________________________________________________________________');
writeln('| Prodi | 2006 | 2007 | 2008 | 2009 | 2010 | 2011 | 2012 | Total |');
writeln('|-----------|------|------|------|------|------|------|------|---------|');
for i:=1 to 5 do
begin
write('|',prodi[i]:11);
for j:=1 to 7 do
begin
write('| ',mhs[i,j]:3,' ');
jumbar:=jumbar+mhs[i,j];
end;
write('| ',jumbar:5,' |');
jumbar:=0;
writeln;
end;
writeln('|-----------|------|------|------|------|------|------|------|---------|');
write('| Total |');
for j:=1 to 7 do
begin
for i:=1 to 5 do
begin
jumkol:=jumkol+mhs[i,j];
end;
write(' ',jumkol:4,' |');
jumkol:=0;
end;
writeln('/////////|');
writeln('|___________|______|______|______|______|______|______|______|_________|');
readln;
writeln('Prodi dengan mahasiswa <50 orang adalah');
for i:=1 to 5 do
begin
for j:=1 to 6 do
if mhs[i,j]<50 then
writeln('prodi ',prodi[i],' tahun ',2006+j,' sebanyak ',mhs[i,j],' orang');
end;
max:=0;
min:=255;
for i:=1 to 5 do
begin
for j:=1 to 6 do
begin
if mhs[i,j]> max then
begin
max:=mhs[i,j];thmax:=2006+j;prodimax:=prodi[i];end;
if mhs[i,j]< min then
begin
min:=mhs[i,j];thmin:=2006+j;prodimin:=prodi[i];end;
end;
end;
{tampilkan}
writeln;
writeln('mahasiswa terbanyak dari prodi ',prodimax,' th ',thmax,' sebanyak ',max);
writeln('mahasiswa tersedikit dari prodi ',prodimin,' th ',thmin,' sebanyak ',min);
end.
0 komentar :
Posting Komentar