program mean_median_modus;
uses wincrt;
type larik = array[1..100] of integer;
var n,m,max : integer;
x,y,f : larik;
jawaban : char;
procedure inputdata(var x:larik; var n:integer);
var i : integer;
begin
write('Write sum of data input: ');readln(n);
for i:=1 to n do
begin
write('File of- ',i,' : ');readln(x[i]);
end;
end;
procedure urutdata(var x:larik; var n:integer);
var i, j, temp : integer;
begin
for i:= 1 to n-1 do
for j:= i to n do
begin
if x[j]
procedure mean(var x:larik; var max,n:integer);
var rata_rata:real; i,jml: integer;
begin
jml:=0;
max:=x[i];
for i:=1 to n do
jml:= jml+x[i];
rata_rata:=jml/n;
write('Average : ',rata_rata:4:0);
writeln;
end;
procedure frekuensi(x:larik; n:integer; var y,f:larik; var m:integer);
var i, j : integer;
begin
for i:=1 to n do
f[i]:=1;
x[n+1]:=x[n]+1;
j:=1;
for i:=1 to n do
if x[i] = x[i+1] then f[j]:=f[j]+1
else
begin
y[j] := x[i];
j := j + 1;
end;
m:=j-1;
end;
procedure maxfrekuensi(f,x:larik; m:integer; var max:integer);
var i:integer;
begin
max:=x[i];
for i:=1 to m do
if f[i]>max then max:=f[i];
end;
procedure modus(y,f:larik; m, max:integer);
var i:integer;
begin
if max = 1 then write('There are not modus')
else
begin
for i:=1 to m do
if f[i]=max then write ('Modus : ',y[i]);
end;
writeln;
end;
procedure median(var x:larik; n:integer);
var md:real; ltk:integer;
begin
if (n mod 2 = 1) then
begin
ltk:=(n div 2)+1;
md := x[ltk]
end
else
begin
ltk:=(n div 2);
md :=(x[ltk]+x[ltk+1])/2;
end;
write('Nilai Median : ',md:4:0);
end;
begin
repeat
clrscr;
gotoxy(20,2);writeln('***************************************** ');
gotoxy(20,3);writeln('* Find Mean Median and Modus * ');
gotoxy(20,4);writeln('***************************************** ');
writeln;
inputdata(x,n);
urutdata(x,n);
mean(x,max,n);
frekuensi(x,n,y,f,m);
maxfrekuensi(f,x,m,max);
modus(y,f,m,max);
median(x,n);
writeln;writeln;
write('Repeat again [Y/T]? : ');readln(jawaban);
until upcase(jawaban)<>'Y';
end.
if we run the statement,we are get output like this :
0 comments:
Post a Comment