Contoh Program Algoritma, Mencari Mean & Median
Program
statistik;
uses
wincrt;
type
statis = array[1..10] of integer;
var
data,frek : statis;
max : integer;
mean : real;
median : real;
modus,modus1 : integer;
i,j,jumlah,temp,imin : integer;
procedure input ;
begin
writeln('Inputkan Data : ');
writeln;
writeln('------------------------');
writeln;
max := 0;
for i := 1 to 10 do
begin
write('Masukan Data ke - ', i, '=');
readln(data[i]);
if data[i] > max then
begin
max := data[i];
end;
end;
writeln;
writeln('------------------------');
end;
procedure rata2;
begin
jumlah := 0;
mean:=0;
for i := 1 to 10 do
begin
jumlah := jumlah + data[i];
end;
mean := jumlah / 10 ;
end;
procedure deret;
begin
for i := 1 to 10 do
begin
imin := i;
begin
for j := i+1 to 10 do
if data[ j ] < data[imin] then
imin := j ;
begin
temp := data[ i ] ;
data[ i ] := data[imin] ;
data[imin] := temp ;
end;
end;
end;
end;
procedure muncul;
begin
{menghitung frekuensi nilai data}
for i:=1 to 10 do
begin
for j:=i+1 to 10 do
if data[i]=data[j] then
frek[i]:=frek[i]+1;
end;
{mencari data dengan frekuensi tertinggi}
modus:=1;
for i:=1 to 10 do
begin
if frek[modus]<frek[i] then
modus:=i;
begin
for j:=1 to 10 do
if frek[modus]=frek[j] then
modus1:=j;
end;
end;
{mencetak modus}
writeln;
if frek[modus]=frek[i] then
write ('modus tidak ada')
else
if frek[modus]=frek[modus1] then
begin
if data[modus]=data[modus1] then
write('modus data adalah ',data[modus],' frekuensinya ',frek[modus]+1)
else
write('modus data adalah ',data[modus],' dan ',data[modus1],' frekuensinya ',frek[modus]+1);
end
else
write('modus data adalah ',data[modus],' frekuensinya ',frek[modus]+1);
end;
procedure tengah;
begin
median := ( data[5] + data[6] ) / 2;
end;
begin
input;
deret;
rata2;
write('data setelah di urutkan : ');
for i:= 1 to 10 do
write(data[i], ' ');
writeln;
writeln('rata - rata : ',mean:0:2);
writeln('nilai max : ', max);
muncul;
writeln;
tengah;
writeln('median : ', median:0:2);
end.
Comments
Post a Comment