program Menghitung_Modus;
uses wincrt;
var
x,frek: array [1..50] of integer;
n,i,j,max: integer;
begin
clrscr;
writeln('Menghitung Modus');
writeln(' ');
writeln(' ');
{input data}
write('Banyak entry data : ');readln(n);
for i:= 1 to n do
begin
write('Masukkan data ke-',i,'= ');readln(x[i]);
end;
{mencari frekuensi data}
for i:= 1 to n do
begin
for j:= 1 to n do
if x[i] = x[j] then
frek [i] := frek [i] + 1
end;
{mencari frekuensi tertinggi}
begin
max := 1;
for i:= 1 to n do
begin
if frek [i] > max then max := frek [i];
end;
end;
{menampilkan frekuensi}
Writeln(‘===================’);
For i:=1 to n do
Begin
Writeln(‘data ke-‘ , i , ’= ‘,x[i],’ muncul ‘, frek[i] ,’ kali’);
End;
Writeln(‘Jadi frekuensi tertingginya=’,max);
{menampilkan modus}
For i:=1 to n do
begin
if frek [i] = max then
writeln(‘modusnya x[‘,i,’] = ‘,x[i]);
end;
readln;
end.