uses wincrt;
var n,i,j,tengah:integer;
a:real;
data:array [0..100] of real;
begin
writeln('SELAMAT DATANG DI PROGRAM STATISTIKA DESKRIPTIF');WRITELN('***==========================***');writeln;
writeln('Berapa jumlah data yang ingin anda dimasukan? (max 100)');
write('silahkan masukan data:');
READLN(N); WRITELN;
{syntax untuk memasukkan data dalam array}
for i:=1 to n do
begin
write('data ke-',i,' = ');
readln(a);
data[i]:=a;
end;
{syntax untuk mengurutkan data pada array}
for i:=1 to n do
for j:=i+1 to n do
begin
if data[i]>data[j] then
begin
data[0]:=data[j];
data[j]:=data[i];
data[i]:=data[0];
end;
end;
for i:=1 to n do begin
writeln(data[i]:0:2);
end;
writeln('min =',data[1]:0:2);
writeln('maks=',data[n]:0:2);
if n mod 2 = 1 then
begin
tengah:=(n+1) div 2;
end
else
begin
tengah:=(n div 2);
end;
if n mod 2 = 1 then writeln('=> nilai median = ',data[tengah]:0:2)
else
writeln('=> nilai median = ',(data[tengah]+data[tengah+1])/2:0:2);
if n mod 2 = 1 then
begin
tengah:=(n+1) div 2;
end;
end.
CONTOH PROGRAM MAX MIN
program min_max;
uses wincrt;
var
a : array[1..100] of real;
i,n : integer;
max,min : real;
begin
writeln ('masukkan banyaknya data:'); readln(n);
max:=-9999;
min:=9999;
clrscr;
for i:=1 to n do begin
writeln ('data ke: ',i); readln (a[i]);
if max<(a[i]) then max := (a[i]);
if min>(a[i]) then min := (a[i]);
end;
writeln('nilai maksimum : ', max:6:2);
writeln('nilai minimum : ', min:6:2);
end.
CONTOH PROGRAM MEAN STDEV VARIANS
program mean_var_stdev;uses wincrt;
var
i,n:integer;a,b,c,d:real;x:array[1..100] of integer;
begin
write('masukkan jumlah data: ');readln(n);
a:=0;
for i:=1 to n do
begin
write('x[',i,']= ');readln(x[i]);
a:=a+x[i];
end;
writeln;
writeln('rata-rata: ',a/n:0:2);
for i:=1 to n do
begin
b:=x[i]-(a/n);
c:=sqr(b);
d:=d+c;
end;
writeln('varians: ',d/(n-1):0:2);
writeln('stddev: ',sqrt(d/(n-1)):0:2);
end.
0 komentar:
Posting Komentar