pascal: pengurutan & pencarian data

program praktek;
uses wincrt;
var
h,acount: array [1..100] of integer;
jumlah, rata : real;
imin,temp,max,i,j,m,n,x,mds: integer;
procedure input;
begin
writeln(‘Output :’);
write(‘Masukkan Banyaknya Data = ‘); readln(n);
for i := 1 to n do
begin
write (‘Data ke-‘,i,’ = ‘); readln(h[i]);
end;
end;
procedure selection_naik;
begin
for i := 1 to n-1 do
begin
imin := i;
begin
for j := i+1 to n do
if h[j] < h[imin] then
imin := j;
begin
temp := h[i];
h[i] := h[imin];
h[imin] := temp;
end;
end;
end;
write(‘Data Setelah Diurutkan Dengan Selection Minimum Naik :’);
writeln;
for i := 1 to n do
begin
write( h[i], ‘ ‘);
end;
end;
procedure plus;
begin
jumlah:=0;
for i:=1 to n do
jumlah:=jumlah+ h[i]  ;
for i := 1 to N do
Begin
write(h[i],’+’);

End;

write(‘ = ‘, jumlah:0:2);

writeln;
writeln(‘Nilai jumlah deret = ‘,jumlah:0:2);
end;

procedure mean;
begin
rata:=0;
for i:=1 to n do
rata:=rata + h[i]  ;
writeln(‘Nilai Rata-Rata (Mean) = ‘,rata/n:0:2);
end;
procedure median;
var
md:real;
ltk:integer;
begin
if (n mod 2 = 1) then
begin
ltk:=(n div 2)+1;
md := h[ltk]
end
else
begin
ltk:=(n div 2);
md :=(h[ltk]+h[ltk+1])/2;
end;
write(‘Nilai Median : ‘,md:1:0);
end;
procedure modus;
begin
max:=0;
for i:=1 to n-1 do
acount[h[i]]:=1;
for i:=1 to n-1 do
begin
if (h[i]=h[i+1]) then
acount[h[i]]:=acount[h[i]]+1
else
if (acount[h[i]]>max) then    
begin
max:=acount[h[i]];
mds:=h[i];
end;
end;
writeln(‘Nilai Yang Sering Muncul (Modus) : ‘,mds,’ Sejumlah ‘,max);
for n:=1 to i-1 do
begin
if ((acount[h[i]]=max)and(h[i]<>mds)) then
begin
mds:=h[i];
writeln(‘Nilai Yang Sering Muncul (Modus) : ‘,mds,’ Sejumlah ‘,max);
end;
end;
writeln;
end;
procedure pencarian;
begin
write(‘Inputkan Angka Yang Anda Cari : ‘); readln(x);
i := 1;
while (i < n) and (h[i] <> x) do
begin
i := i+1;
end;
if (h[i]=x) then
writeln (‘Ditemukan Pada Deret Ke-‘,i)
else
writeln (‘Tidak Ditemukan !!!’);
end;

begin
input;
writeln(‘===============================================’);
selection_naik;
writeln;
writeln(‘===============================================’);
plus;
mean;
median;
writeln;
modus;
writeln(‘===============================================’);
pencarian;
writeln;
writeln;
writeln;
writeln(‘====================BY========================’);
writeln(‘===============HASAN BASRI====================’);
end.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s