Tinkerbell

Minggu, 18 Desember 2011

CONTOH PROGRAM PASCAL STATISTIKA

CONTOH PROGRAM STATISTIKA DESKRIPTIF
program atatistika_deskriptif;
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 PELUANG BINOMIAL
program binomial;
uses wincrt;
var
i,j,k,n,x:longint;
a,b,c,d,e,p:real;
begin
writeln('nilai n = ');readln(n);
writeln('nilai x dari n = ');readln(x);
writeln('peluang sukses p = ');readln(p);
a:=1;
b:=1;
c:=1;
d:=1;
e:=1;
for i:=1 to n do
a:=a*i;
for j:=1 to x do
begin
b:=b*j;
c:=c*p;
end;
for k:=1 to (n-x) do
begin
d:=d*k;
e:=e*(1-p);
end;
writeln(a/(b*d)*c*e:0:4);
end.

CONTOH PROGRAM MEAN

program rata_rata;
uses wincrt;
var
i,n: integer;
x,sum,mean:real;
begin
write('banyaknya data = ');
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('rata-rata = ',mean:9:4);
end.

CONTOH PROGRAM MEDIAN
Program median;
Uses Wincrt;
Var
x: array [1..100] of integer;
n,i,pos:integer;
md:real;
lagi:char;
Begin
lagi:='y';
while lagi='y' do
begin
writeln('=============');
Writeln('Program median');
Writeln('=============');
Writeln;
writeln('*dalam program mini ini, data yang harus dimasukkan nanti harus sudah urut*');
writeln;
Write('Masukkan Jumlah Data (n): ');
readln(n);
clrscr;
Writeln;
For i:= 1 to n do
Readln(x[i]);
Writeln;
For i:= 1 to n do
if (n mod 2 = 1) then
begin
pos:=(n div 2)+1;
md:=x[pos];
end
else
begin
pos:=(n div 2);
md:=(x[pos]+x[pos+1])/2;
end;
writeln;
Writeln('Median dari data berjumlah ', n,' tadi adalah : ',md:4:2);
writeln;
writeln('*terimakasih sudah menggunakan program ini*');
writeln('hitung lagi?');
readln(lagi);
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.


About Author