Skip to content

Contoh penggunaan procedure pada Turbo Pascal

April 27, 2009

program Menu_Program;
uses crt;
var
a:byte;
i,n,x : integer;
sigmay,sigmax,ratax,ratay,sigma,sigma1,sigma2,cov,varian : real;
rerata,hsl : real;
procedure hapus_layar;
begin
clrscr;
end;
procedure mean;
begin
writeln(‘Menghitung Mean dari beberapa Data’);
writeln(‘———————————-‘);
write(‘Masukkan banyak data yang akan di input :’);
readln(n);
sigma:=0;
for i:=1 to n do
begin
write(‘Input x’,i,’ :’);
readln(x);
sigma:=sigma + x;
end;
rerata := sigma/n;
writeln(‘Mean dari data – data terebut adalah ‘,rerata:5:2);
readln;

end;
procedure varians;
begin
writeln(‘Menentukan Varians’);
writeln(‘——————‘);
write(‘Masukan banyak data : ‘);
readln(n);
while n<2 do
begin
writeln(‘Banyak data harus lebih dari 2’);
write(‘Masukkan banyak data : ‘);
readln(n);
end;
sigma1 := 0;
sigma2 := 0;
for i := 1 to n do
begin
write(‘Masukkan data’,i,’ : ‘);
readln(x);
sigma1:=sigma1 + x;
sigma2:=sigma2 + (x*x);
end;
hsl :=(n*sigma2 – (sigma1*sigma1))/(n*(n-1));
writeln(‘Varians = ‘,hsl:5:2);
readln;
end;
procedure covar;
var
x,y,px,py,k : array [1..100] of real;
begin
write(‘n = ‘); readln(n);
sigmax := 0;
sigmay := 0;
for i := 1 to n do
begin
write(‘x = ‘); readln(x[i]);
write(‘y = ‘); readln(y[i]);
sigmax := sigmax + x[i];
sigmay := sigmay + y[i];
end;
ratax := sigmax/n;
ratay := sigmay/n;
sigma := 0;
for i := 1 to n do
begin
px[i] := x[i] – ratax;
py[i] := y[i] – ratay;
k[i] := px[i]*py[i];
sigma := sigma + k[i];
end;

Download source code lengkapnya di sini..

Ini contoh prosedur program statistik..Keren kan..

One Comment
  1. mas, ada materi olimpiade komputer sma nggak??
    visit : jendule.blogspot.com

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: