1) Rata-Rata
program rata;
var
i,n
: integer;
x,sum,mean
: real;
begin
readln
(n); sum:=0;
for
i:= 1 to n do
begin
writeln
('data ke', i, '=');
readln
(x);
sum:=
sum + x;
end;
mean:=
sum/n;
writeln
(n, 'rata-rata=', mean: 9: 4);
end.
2) Mencari Mean dan Varian
PROGRAM jharray;
USES WINCRT;
VAR
x:array[1..100] of real;
mean, rata,va: real;
n,j,i:
integer;
BEGIN
write ('masukkan n banyaknya angka ');
readln (n);
for i :=1 to n do
begin
write ('n ke' ,i,' = ');
readln (x [i]);
end;
rata:=0;
for i:=1 to n do
rata:=rata + x [i] ;
mean:= rata/n;
writeln('mean=',mean :2:2);
va := 0 ;
for i:= 1 to n do
begin
va := va
+ ((sqr((x [i]) - mean)) / (n-1) );
end;
writeln ('varian=',va:2:3) ;
writeln ( 'standar deviasi=', sqrt (va):2:3) ;
end.
3) Mencari Modus
program mode_statistics;
uses wincrt;
var
a,modus : array [1..100] of real;
b : array [1..100] of integer;
i,j,n,mode : integer;
begin
write('n = ');readln(n);
for i:=1 to n do
begin
write('data ke-',i,' = ');readln(a[i]);
end;
for i:=1 to n-1 do
begin
b[i]:=1;
for j:=i+1 to n do
if a[i]=a[j] then
b[i]:=b[i]+1;
end;
mode:=1;
for i:=1 to n do
if b[i]>=mode then
begin
mode:=b[i];
modus[1]:=a[i];
end;
for j:=1 to n do
if b[j] = mode then
modus[j]:=a[j];
writeln('modus adalah ');
for i:=1 to n do
begin
if modus[i]<>0 then
begin
write(modus[i]:0:0);
writeln;
end;
end;
writeln('yang muncul sebanyak ',mode);
end.
Tidak ada komentar:
Posting Komentar