program statistika_deskriptif;
uses wincrt;
var
x:array [1..100] of real;
mean,rata,varians,s_2,standar_deviasi,s_d:real;
n,j,i:integer;
begin
write('masukkan n banyaknya angka = ');
readln(n);
for i:=1 to n do
begin
write(i, ' = ' );
readln(x[i]);
end;
rata:=0;
for i:=1 to n do
rata:=rata+x[i];
mean:=rata/n;
writeln('mean= ',mean:0:0);
varians:=0;
for i:=1 to n do
begin
write('varians= ');
readln(s_2);
s_2:=sqr(x[i]-mean);
writeln('varians= ',s_2:0:0);
end;
s_d:=0;
for i:=1 to n do
begin
write('standar deviasi= ');
writeln(s_d);
s_d:=sqrt(s_2);
writeln('standar deviasi= ',s_d:0:0);
end;
end.
Kamis, 05 Januari 2012
Label:
Contoh Program Pascal
PROGRAM BINOMIAL
program binomial;
uses wincrt;
var i,j,k,n,x: longint;
a,b,c,d,e,p:real;
begin
readln(n,x,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);
end.
Label:
Contoh Program Pascal
Senin, 19 Desember 2011
PROGRAM DETERMINAN DAN INVERS
program determinan_invers;
uses wincrt;
var
x,y:array [1..50,1..50] of integer;
i,j,det:integer;
begin
writeln('Masukkan nilai matriks ordo 2 x 2 !');
for i:=1 to 2 do
for j:=1 to 2 do
begin
write('nilai x[',i,',',j,'] = ');readln(x[i,j]);
end;
writeln;
writeln('Bentuk matriks nya');
for i:=1 to 2 do
begin
for j:=1 to 2 do
write(x[i,j]:5);
writeln;
end;
det:=x[1,1]*x[2,2]-x[1,2]*x[2,1];
writeln;
writeln('Determinan matriks = ',det);
y[1,1]:=x[2,2];
y[1,2]:=-x[2,1];
y[2,1]:=-x[1,2];
y[2,2]:=x[1,1];
writeln;
writeln('Invers matriks nya');
for i:=1 to 2 do
begin
for j:=1 to 2 do
write(y[i,j]/det:8:2);
writeln;
end;
end.
Label:
Contoh Program Pascal
PROGRAM MATRIKS
- Penjumlahan Matrik
program matrik_penjumlahan;
uses wincrt;
var a,b,c: array[1..10,1..10] of integer;
i,j,k1,k2,b1,b2,sum,r:integer;
begin
write('Masukkan baris Matrik A = ');readln(b1);
write('Masukkan kolom Matrik A = ');readln(k1);
write('Masukkan baris Matrik B = ');readln(b2);
write('Masukkan kolom Matrik B = ');readln(k2);
for i:=1 to b1 do
for j:=1 to k1 do
readln(a[i,j]);
writeln;
for i:=1 to b2 do
for j:=1 to k2 do
readln(b[i,j]);
writeln;
writeln('Matrik A');
writeln('==================');
for i:=1 to b1 do
begin
for j:=1 to k1 do
write(a[i,j],' ');
writeln;
end;
writeln;
writeln('Matrik B');
writeln('===================');
for i:=1 to b2 do
begin
for j:=1 to k2 do
write(b[i,j],' ');
writeln;
end;
writeln;
writeln('Matrik A*B');
writeln('================');
for i:=1 to b1 do
begin
for j:=1 to k2 do
begin
sum:=0;
for r:=1 to k1 do
sum:=sum+a[i,r]*b[r,j];
c[i,j]:=sum;
write(c[i,j]:2,' ');
end;
writeln;
end;
end.
- Perkalian Matriks
program perkalian_matrix;
uses crt;
var
a,b,c : array [1..50,1..50] of integer;
i,j,k,x,y,z : integer;
begin
clrscr;
writeln(‘Ukuran matrix A’);
write(‘Baris : ‘);
readln(x);
write(‘Kolom : ‘);
readln(y);
writeln;
writeln;
writeln(‘Ukuran matrix B’);
writeln(‘Baris : ‘,y);
write(‘Kolom : ‘);
readln(z);
for i:=1 to x do
for j:=1 to y do
begin
write(‘Elemen A[',i,',',j,'] : ‘);
readln(a[i,j]);
end;
writeln;
for i:=1 to y do
for j:=1 to z do
begin
write(‘Elemen B[',i,',',j,'] : ‘);
readln(b[i,j]);
end;
for i:=1 to x do
for j:=1 to z do
for k:=1 to y do
c[i,j] := c[i,j] + a[i,k]*b[k,j];
writeln;
writeln;
writeln(‘Hasil dari perkalian Matrix A dengan Matrix B adalah : ‘);
Writeln;
for i:=1 to x do
begin
for j:=1 to z do
write(c[i,j],’ ‘);
writeln;
end;
writeln;
readln;
end.
Label:
Contoh Program Pascal
CONTOH PROGRAM PASCAL
- Contoh 1 :
uses wincrt;
var nama:string;
umur,tahunlahir:integer;
begin
write('Nama : ');
readln(nama);
write('Tahun Lahir : ');
readln(tahunlahir);
umur:= 2011 - tahunlahir;
write('Umur : ', umur);
end.
- Contoh 2 :
uses wincrt;
var b,n:integer;
begin
n:=0;
repeat b:=1+3*n;
n:=n+1;
write (b, ' ');
until
n=6;
end.
- Contoh 3 :
program mahasiswa;
uses wincrt;
var
i:integer;
begin
i:=1; write(i);write(' ');
repeat
i:=i+3;
write(i);write(' ');
until i=16;
end.
- Contoh 4 :
program pemangkatan;
uses wincrt;
var a,b,i:integer;n:real;
begin
write('A = ');readln(a);
write('B = ');readln(b);
n:=1;
for i:=1 to abs(b) do
n:=n*a;
if (b>=0) then
begin
writeln('A pangkat B = ',n);
end
else
begin
writeln('A pangkat B = ',1/n);
end
end.
- Contoh 5 :program faktorial;
uses wincrt;
var a:real;
n,i:integer;
begin
write('n = ');readln(n);
write('n faktorial = ');
a:=1;
if n<0 then write('tidak terdefinisi')
else
if n<2 then
write(1)
else
begin
for i:=n downto 2 do
begin
write(i,' x ');
a:=a*i;
end;
write(1,' = ',a:0:0);
end;
end.
- Contoh 6 :program segitiga_pascal;
uses wincrt;
var
n,i,j,x:integer;
begin
n:=1;
read(x);
writeln(x);
for i:=1 to x do
begin
for j:= 1 to i do
begin
write(n,' ');
n:=n+1;
end;
writeln(' ');
end;
end.
- Contoh 7 :program deret_fibbonacci;
uses wincrt;
var a,b,c,i,n: integer;
begin
write('masukkan n = ');
readln(n);
a:=1; b:=0;
for i:=1 to n do
begin
c:=a+b;
a:=b;
b:=c;
write(c,',');
end;
end.
Label:
Contoh Program Pascal
PROGRAM KONVERSI
program konversi_biner_desimal;
uses wincrt;
var
desimal,d,sisa,biner:integer;
begin
write('Angka Desimal');readln(desimal);
d:=0;
repeat
sisa:=desimal mod 2;
desimal:=desimal div 2;
if (d=0) then
d:=1
else
d:= d * 10;
biner:= biner + sisa * d;
until desimal=0;
write('Biner = ',biner);
end.
uses wincrt;
var
desimal,d,biner,sisa:longint;
begin
write('Biner = ');readln(biner);
d:=0;
repeat
sisa:=biner mod 10;
biner:=biner div 10;
if (d=0) then
d:=1
else
d:= d*2;
desimal:=desimal+sisa*d;
until biner=0;
write('Angka Desimal = ',desimal);
end.
Label:
Contoh Program Pascal
ALGORITMA
Algoritma..???
mungkin kita masih bingung apa itu algoritma dan gimana cara pengubahannya..
Ayo, baca dengan antusias yaa..:-)
Konversi Desimal ke Biner
mungkin kita masih bingung apa itu algoritma dan gimana cara pengubahannya..
Ayo, baca dengan antusias yaa..:-)
Konversi Desimal ke Biner
- Mulai d = 1, biner 0
- Baca desimal
- Desimal = desimal div 2
- Sisa = desimal mod 2
- d baru = d x 10
- biner baru = biner + (sisa x d)
- Jika desimal = 0, pergi langkah 9
- Jika desimal tidak 0, pergi ke langkah 3
- Cetak biner
- Selesai
- Mulai
- Baca biner
- Biner = biner div 10
- Sisa = biner mod 10
- d baru = d x 2
- Desimal baru = (sisa x d) + desimal
- Jika biner 0, pergi ke langkah 9
- Jika biner tidak 0, maka ulangi mulai langkah 3
- Cetak desimal
- Selesai
Label:
Uraian Tentang Pascal
Langganan:
Postingan (Atom)