CONTOH PROGRAM PASCAL

Posted: March 1, 2011 in Pascal

program pengurangan;
var
x,y,z:integer;
begin
x:=5;
y:=78;
z:=x-y;
writeln(‘Hasil pengurangan’,x,’dan’,y,’adalah’,z);
readln;
end.

program perkalian;
var
x,y,z:integer;
begin
x:=5;
y:=78;
z:=x*y;
writeln(‘Hasil perkalian’,x,’dan’,y,’adalah’,z);
readln;
end.

program tipe_char;
var karakter_angka:char;
huruf:char;
begin
karakter_angka:=’I’;
huruf:=’G’;
writeln(huruf);
readln;
end.

program baca;
var A:real;
begin
write(‘Masukan niali A:’);readln(A);
Writeln(‘Nilai yg anda masukan adalah:’,A);
readln;
end.

program luas_lingkaran;
var
r,L:real;
const
phi=3.14;
begin
write(‘masukan jari-jari= ‘);readln(r);
L:=phi*sqr(r);
writeln(‘Luas lingkaran=’,L);
readln;
end.

program sejajar;
begin
writeln(‘nama’,   ‘|’:10,’agama’,  ‘|’:20);
writeln(‘cakep’,  ‘|’:10,’islam’,  ‘|’:20);
writeln(‘ganteng’,’|’:10,’kristen’,’|’:20);
readln;
end.

program penambahan;
var
x,y,z : imteger;
begin
x:=5;
y:=78;
z:=x+y;
writeln(‘Hasil penjumlah’ ,x,’ dan ‘,y,’adalah’ ,z);
readln
end.

program nilai;
var A : imteger;
begin
write(‘masukan nilai A:’);readln(A);
writeln(‘Nilai yg anda masukan adalah:’,A);
readln;
end.

program perkalian_nilai;
var A,B,Z : integer;
begin
write(‘masukan nilai A:’);readln(A);
write(‘masukan nilai B:’);readln(B);
Z:=A*B;
writeln(‘Hasil perkalian A dan B adalah:’,Z);
readln;
end.

program ganjil_genap;
var bilangan : integer;
begin
write(‘masukan angka’):readln(bilangan);
if(bilangan mod 2 = 0)then
writeln(bilangan,’adalah genap’)
else
writeln(bilangan,’adalah ganjil’);
readln;
end.

program kondisi;
var nile : integer;
begin
write(‘masukan nilai:’);readln(nile);
if (nile>80) then write(‘A’)
else if (nile>60) then write(‘B’)
else write(‘E’)
readln;
end.

program nilai_case;
var nile : integer;
begin
write(‘masukan nilai:’);readln(nile);
case nile of
0..25  : writeln(‘Nilai = E’);
26..39 : writeln(‘Nilai = D’);
40..64 : writeln(‘Nilai = C’);
65..79 : writeln(‘Nilai = B’);
80..100: writeln(‘Nilai = A’);
else
writeln(‘Tidak ada nilai yg d maksud’);
end;
readln;
end.

program vokal_konsonan;
var abc : char ;
begin
write (‘masukan huruf’); readln(abc);
if (abc:’a’); then
writeln(abc,’adalah huruf vokal’);
else if (abc:’i’); then
writeln(abc,’adalah huruf vokal’);
else if (abc:’u’); then
writeln(abc,’adalah huruf vokal’);
else if (abc:’e’); then
writeln(abc,’adalah huruf vokal’);
else if (abc:’o’); then
writeln(abc,’adalah huruf vokal’);
else
writeln(abc, ‘adalah huruf konsonan’);
readln;
end.

program ulangterus;
begin
repeat
write(‘pencet no 1’); readln(masukan);
if (masukan<>1)then
writeln(‘wwwweeeeeee ngeyel!!!’);
until(masukan=1);
writeln(‘baguuzzz!!!’);
Readln;
End.

program pengulangan;
var x, y, jumlah : integer;
k : char;
begin
repeat
write(‘masukan nilai x ‘); readln(x);
write(‘masukan nilai y ‘); readln(y);
jumlah=x+y;
writeln(jumlah)
write(‘lagi..? (ya/tidak)’); readln(k);
if (k=y)then
writeln(‘wokey’);
until(k<>y);
writeln(‘bye…’);
Readln;
End.

Program KOMBINASI;
uses crt;
var f1,f2,f3:longint;
n,r,delta:integer;
c: real;
Procedure facto( n:integer; var f:longint);
var i:integer;
begin
f:=1;
for i:=1 to n do
f:= f * i;
end;
{======================PROGRAM UTAMA=======================}
Begin
clrscr;
gotoxy(12,3);
write(‘Kita akan menghitung nilai kombinasi dari suatu angka’);
gotoxy(19,4);
writeln(‘Yang mempunyai rumus : rCn = n!/(r!(n-r)!)’);
gotoxy(20,5);
writeln(‘Nilai r harus lebih kecil/sama dengan n’);
writeln;gotoxy(28,6);
write(‘Masukkan nilai n :’,’ ‘);readln(n);
writeln;gotoxy(28,8);
write(‘Masukkan nilai r :’,’ ‘);readln(r);
facto(n,f1);
facto(r,f2);
delta:=(n-r);
facto(delta,f3);
c:= f1/(f2*f3);gotoxy(30,10);
write(‘Hasilnya :’,’ ‘,c:2:0);
readln;
end.

program fakto;
uses crt;
var
procedure facto(var n : integer);
var i : integer
begin
for i = 1 to n do
begin
if (n mod i = 0)then
write(i);
end;
end;
begin
write(‘masukan nilai x :’,’ ‘); readln(x);
facto(x);
readln;
end.

PROGRAM FAKTORIAL;
Uses crt ;
Var i , N , Hsl : integer
Function Fakto(N:integer):integer ;
Var Fak: integer ;
Begin
if (N=0) or (N=1) then
Fakto:= 1
else
Fakto:= N*Fakto(N-1) ;
end;
Begin
clrscr;
write(‘Faktorial berapa yang anda ingin hitung : ‘) ;
readln(N) ;
writeln(‘Hasil perhitungan : ‘,Fakto(N)) ;
readln ;
end.

program larik;
uses crt;
var N : Array [1..6] of integer;
begin
clrscr;
write (‘Angka1 : ‘); readln(N[1]);
write (‘Angka2 : ‘); readln(N[2]);
N[3] := N[1] + N[2];
N[4] := N[1] * N[2];
N[5] := N[1] div N[2];
N[6] := N[1] – N[2];
writeln(‘hasil penjumlahan : ‘,N[3]);
writeln(‘hasil perkalian : ‘,N[4]);
writeln(‘hasil pembagian : ‘,N[5]);
writeln(‘hasil pengurangan : ‘,N[6]);
readln;
end.

program rata;
uses crt;
var  N : Array [1..6] of integer;
hasil : real;
i, jml : integer;
begin
clrscr;
for i := 1 to 5 do
begin
write(‘angka ‘,i,’ :’); readln(N[i]);
end;
jml := 0;
for i := 1 to 5 do
begin
jml := jml + N[i];
end;
hasil := jml / 5;
writeln(‘rata2 dari 5 angka tersebut adalah : ‘,hasil);
readln;
end.

program gaji;
Uses crt;
Var nama:string[20];jabatan:string;
Tunj,ppn,gajibersih, total:real;
nilai:string;
Begin
Clrscr;
Write(‘Nama Karyawan     : ‘); readln(nama);
Write(‘Masukkan Jabatan  : ‘); readln(jabatan);
If  (jabatan=’Direktur’) or (jabatan=’direktur’) then
Begin
Nilai := ‘A’;
End
Else If  (jabatan=’Manager’) or (jabatan=’manager’) then
Begin
Nilai := ‘B’;
End
Else If  (jabatan=’Karyawan’) or (jabatan=’karyawan’) then
Begin
Nilai := ‘C’;
End
Else
Begin
Nilai := ‘D’;
End;
Writeln(‘Gaji Bersih      : Rp.’,Nilai);
Readln;
End.

program desitobin;
uses crt;
var
biner : array[1..8] of integer;
i,des,a,b,t:integer;
begin
clrscr;
t:=9;
write(‘masukan desimal : ‘);readln(des);
repeat
b:=des mod 2;
t:=t-1;
biner[t]:=b;
a:=des div 2;
des:=a;
until des = 0;
write(‘binernya adalah : ‘);
for i := 1 to 8 do
begin
write(biner[i]);
delay(100);
end;
readln;
end.

program pointer;
uses wincrt;
var
a, b, c : ^integer;
begin
new(a); new(b); new(c);
a^:=30; b^:=20;
c^:=a^+b^;
write(c^);
readln;
end.

program rekot;
type data = record
nama : String;
umur : integer;
jk   : char;
end;
var mhs : data;
begin
write(‘Masukan Nama          : ‘); readln(mhs.nama);
write(‘Masukan Umur          : ‘); readln(mhs.umur);
write(‘Masukan Jenis Kelamin : ‘); readln(mhs.jk);
writeln;
//menampilkan
writeln(‘nama : ‘, mhs.nama);
writeln(‘umur : ‘, mhs.umur);
writeln(‘jenis kelamin : ‘, mhs.jk);
readln;
end.

program rekotpoin;
type Pmhs = ^Tmhs;
Tmhs = record
nama : String;
umur : integer;
jk   : char;
end;
var m : Pmhs;
begin
new(m);
write(‘Masukan Nama          : ‘); readln(m^.nama);
write(‘Masukan Umur          : ‘); readln(m^.umur);
write(‘Masukan Jenis Kelamin : ‘); readln(m^.jk);
writeln;
//menampilkan
writeln(‘nama : ‘, m^.nama);
writeln(‘umur : ‘, m^.umur);
writeln(‘jenis kelamin : ‘, m^.jk);
dispose(m);
readln;
end.

SEKIAN DULU DAN SELAMAT DICOBA!!🙂

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