0% found this document useful (0 votes)
170 views6 pages

Program Menghitung Mean, Median, Dan Modus

1. The document describes two programs that calculate the mean, median, and mode of a data set. 2. The first program performs the calculations sequentially within the main program. 3. The second program implements the calculations as functions to modularize the code and make it more readable. Input is handled by a separate input procedure.

Uploaded by

Tenti Amelya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
170 views6 pages

Program Menghitung Mean, Median, Dan Modus

1. The document describes two programs that calculate the mean, median, and mode of a data set. 2. The first program performs the calculations sequentially within the main program. 3. The second program implements the calculations as functions to modularize the code and make it more readable. Input is handled by a separate input procedure.

Uploaded by

Tenti Amelya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

1.

Program menghitung mean, median, dan modus

program Ratamedianmodus;

uses crt;

type

larik = array [1..100] of integer;

var

x,mo : larik;

Total, i, j, n, temp, modus : integer;

mean, median : real;

begin

clrscr;

write('Masukkan jumlah data : '); readln(n);

writeln;

Total := 0;

for i:= 1 to n do

begin

write ('Masukkan data ke-', i,' Anda : '); readln(x[i]);

Total := Total + x[i] ;

end;

writeln;

mean := Total / n ;

write ('Hasil perhitungan meannya adalah : ');

writeln(mean:2:2);

writeln;

writeln('Urutan Data : ');

for i := 1 to (n-1) do

for j := n downto i+1 do


if x[j] < x[j-1] then

begin

temp := x[j];

x[j] := x[j-1];

x[j-1] := temp;

end;

for i := 1 to n do

writeln(x[i]);

writeln;

writeln('Median dan Modus');

writeln('================');

if n mod 2 = 0 then

median :=(x[n div 2] + x[(n div 2)+1]) / 2

else

median := x[(n div 2) + 1];

writeln('Median = ',median:0:2);

for i := 1 to n do

begin

mo[i] := 0;

for j:= i + 1 to n do

begin

if x[i] = x[j] then

mo[i] := mo[i] + 1;

end;
end;

for i := 1 to n do

begin

if mo[i] > 0 then

modus := x[i];

end;

writeln('Modus = ',modus);

readln;

end.
2. Program menghitung mean, median, dan modus menggunakan function

program Ratamedianmodus;

uses crt;

type

larik = array [1..100] of integer;

var

x : larik;

i, j, n : integer;

procedure input;

begin

clrscr;

write('Masukkan jumlah data : '); readln(n);

for i:= 1 to n do

begin

write ('Masukkan data ke-', i,' Anda : '); readln(x[i]);

end;

end;

Function mean:real;

var Total : real;

begin

Total := 0;

for i := 1 to n do

begin

Total := Total + x[i];

end;

mean := Total / n ;
end;

Function median:real;

var temp : integer;

begin

for i := 1 to (n-1) do

for j := n downto i+1 do

if x[j] < x[j-1] then

begin

temp := x[j];

x[j] := x[j-1];

x[j-1] := temp;

end;

if n mod 2 = 0 then

median :=(x[n div 2] + x[(n div 2)+1]) / 2

else

median := x[(n div 2) + 1];

end;

Function modus:integer;

type dus = array [1..100] of integer;

var mo:dus;

begin

for i := 1 to n do

begin

mo[i] := 0;

for j:= i + 1 to n do
begin

if x[i] = x[j] then

mo[i] := mo[i] + 1;

end;

end;

for i := 1 to n do

begin

if mo[i] > 0 then

modus := i;

end;

end;

{Main Program}

begin

input;

mean;

median;

modus;

writeln('Mean : ',mean:0:2);

writeln('Median : ',median:0:2);

writeln('Modus : ',x[modus]);

readln;

end.

You might also like