Friday, August 20, 2010

Kumpulan Program Pascal

Kumpulan Program Pascal
Kumpulan program pascal ini merupakan kumpulan latihan saat saya belajar bahasa
pemrograman pascal. Saya menggunakan Turbo Pascal for Windows (TPW) Versi
1.5 sebagai kompilernya. Mungkin ada kekurangan disana sini, tapi mudah-mudahan
kumpulan program ini bermanfaat bagi anda yang telah membaca blog saya .
bahasa pemrograman pascal:
                    
Program Menghitung_Jarak

Uses WinCrt;
var
x1,x2,y1,y2:integer;
d:real;
begin
Writeln('Program Menghitung Jarak Titik A dan B');
Writeln('==========dede si anak online==========');
Writeln;
Write('Masukan Nilai A (X1): ');readln(x1);
Write('Masukan Nilai B (X2): ');readln(x2);
Write('Masukan Nilai A (Y1): ');readln(y1);
Write('Masukan Nilai B (Y2): ');readln(y2);
d:=sqrt(sqr(x2-x1)+sqr(y2-y1));
Writeln;
Writeln('Jadi Jarak Titik A ke B Adalah: ',d:4:2);
end.

Output:





Program konversi suhu fareinheit ke celcius:



Uses WinCrt;
var f,c:real;
begin
Writeln('Program Konversi Fareinheit Ke Celcius');
Writeln('==========dede si anak online=========');
Writeln;
Write('Masukan Suhu dalam Farenheit: ');readln(f);
c:=5/9*(f-32);
Writeln;
Writeln('Jadi Suhu Dalam Celcius Adalah: ',c:4:2);
Writeln(‘progam versi 1.0 by dede’);
end.

Output:



Progam konversi waktu:
Uses Wincrt;
Var j,m,d,h:integer;
begin
Writeln('  Program Konversi Waktu  ');
Writeln('===dede sii anak online===');
Writeln;
Write('Masukkan Jumlah Jam : ');readln(j);
Write('Masukkan Jumlah Menit : ');readln(m);
Write('Masukkan Jumlah Detik : ');readln(d);
Writeln;
h:=(j*3600)+(m*60)+d;
Writeln('Jadi Hasil Konversi : ',h,' Detik');
Writeln(‘progam versi 1.0 by dede’);
end.


Output:


Progam  penghitung jam dalam perdetik:
Uses WinCrt;
var j,m,d,dm,sisa,sisa1:integer;
begin
Writeln('Program penghitung jam dalam detik’);
Writeln('=====dede sii anak online========');
Writeln;
Write('Masukkan Jumlah Detik : ');readln(dm);
if (dm/3600)>0 then
begin
j:=dm div 3600;
sisa:=dm-(j*3600);
end
else
begin
j:=0;
sisa:=dm;
end;
if (sisa/60)>0 then
begin
m:=sisa div 60;
sisa1:=sisa-(m*60);
end
else
begin
m:=0;
sisa1:=sisa;
end;
d:=sisa1;
Writeln;
Writeln('Hasil => ',j,' jam ',m,' menit ',d,' detik');
Writeln(‘progam versi 1.0 by dede’);
end.


Output:

Program Menghitung Selisih Waktu;

Uses WinCrt;
Var j,m,d,h,j1,m1,d1,h1,hj,hm,sl,sisa,sisa1:longint;
Begin
Writeln('**********Program Menghitung Selisih Waktu*********’);
Writeln('===============dede sii anak online================');
Writeln;
Write(‘WAKTU PERTAMA’);
Writeln;
Write('masukan jam   : ');readln(j);
Write('masukan Menit : ');readln(m);
Write('masukan Detik : ');readln(d);
Writeln('====================================================');
Write(‘WAKTU KEDUA’);
Writeln;
Write('masukan jam   : ');readln(j1);
Write('masukan Menit : ');readln(m1);
Write('masukan Detik : ');readln(d1);
h:=(j1*3600)+(m1*60)+d1;
h1:=(j*3600)+(m*60)+d;
sl:=h1-h;
if (sl/3600)>0 then
begin
hj:=sl div 3600;
sisa:=sl-(hj*3600);
end
else
begin
hj:=0;
sisa:=sl;
end;
if (sisa/60)>0 then
begin
hm:=sisa div 60;
sisa1:=sisa-(hm*60);
end
else
begin
hm:=0;
sisa1:=sisa;
end;
Writeln;
Writeln('Selisih Waktu: ',hj,' jam ',hm,' Menit ',sisa1,' Detik');
Writeln(‘progam versi 1.0 by I GEDE SUJANA’);
End.


Output:


Program Mengurutkan Bilangan:

Uses Wincrt;
Var A,B,C:integer;
Begin
Writeln('   Program Mengurut Bilangan versi 1.0 by dede    ');
Writeln('==============dede sii anak online================');
Writeln;
Write('Masukkan Nilai pertama: ');readln(A);
Write('Masukkan Nilai kedua: ');readln(B);
Write('Masukkan Nilai selanjutnya: ');readln(C);
Writeln;
if (A<=B) and (A<=C) then
if (B<=C) then
Writeln(A,' ',B,' ',C)
else
Writeln(A,' ',C,' ',B)
else if (B<=A) and (B<=C) then
if (A<=C) then
Writeln(B,' ',A,' ',C)
else
Writeln(B,' ',C,' ',A)
else if (C<=A) and (C<=B) then
if (A<=B) then
Writeln(C,' ',A,' ',B)
else
Writeln(C,' ',B,' ',A)
End.

Output:


Program Menentukan Segitiga:

Uses Wincrt;
Var A,B,C,X,Y:integer;
Begin
Writeln('****Program Menentukan Segitiga Versi 1.0 by dede****');
Writeln('=================dede sii anak online================');
Writeln;
Write('Masukkan Sisi A: ');readln(A);
Write('Masukkan Sisi B: ');readln(B);
Write('Masukkan Sisi C: ');readln(C);
Writeln;
X:=sqr(C);
Y:=sqr(A)+sqr(B);
if (X
Writeln('Segitiga Lancip')
else if (X=Y) then
Writeln('Segitiga Siku-Siku')
else
Writeln('Segitiga Tumpul')
End.

Output :


Program Menghitung Nilai Rata-Rata:

Uses Wincrt;
Var n,x,i,tot:integer;
rata:real;
Begin
Writeln(‘*****Program Menghitung Rata-Rata******');
Writeln('*****=====dede sii anak online====*****');
Writeln;
Write('Masukkan banyaknya Nilai: ');readln(n);
Writeln;
Writeln('Masukkan Nilai: ');
tot:=0;
For i:= 1 to n do
Begin
Readln(x);
tot:=tot+x;
End;
rata:=tot/n;
Writeln;
Writeln('Total Bilangan: ',tot:6);
Writeln('Rata-Rata : ',rata:6:2);
Writeln(‘progam versi 1.0 by dede’);
End.
Output:
















Program Solusi_Bilangan_Bulat

Uses Wincrt;
Var i,n,x,y,z:integer;
Begin
Writeln('program olusi Bilangan Bulat versi 1.0 by dede');
Writeln('=============dede sii anak online=============');
Writeln;
for x:= 0 to 25 do
for y:= 0 to 25 do
for z:= 0 to 25 do
if (x+y+z=25) then
begin
writeln(x,' ',y,' ',z);
readln;
end;
End.
Output:








*Program Array:

Uses Wincrt;
Var x: array [1..100] of integer;
n,i,max,min,tot,pos:integer;
rt,sdt,sd,md:real;
Begin
Writeln('************Program Array versi 1.2 by dede************');
Writeln('================dede sii anak online===================');
Writeln;
Write('Masukkan banyaknya angka setelah itu tekan ENTER kemudian masukan angka:');readln(n);
Writeln;
For i:= 1 to n do
Readln(x[i]);
Writeln;
Write('Data Yang Telah Dimasukkan: ');
max:=x[1];
min:=x[1];
tot:=0;
sdt:=0;
For i:= 1 to n do
Begin
Write(x[i],' ');
if (max
max:=x[i]
else
min:=x[i];
tot:=tot+x[i];
End;
rt:=tot/n;
For i:= 1 to n do
Begin
sdt:=sdt+sqr(x[i]-rt);
End;
sd:=sqrt(sdt/(n-1));
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('Nilai Maximal : ',max);
Writeln('Nilai Minimal : ',min);
Writeln('Nilai Rata-Rata : ',rt:4:2);
Writeln('Standar Deviasi : ',sd:4:2);
Writeln('Median : ',md:4:2);
End.


Output:


Program Polindrom:

Uses Wincrt;
Var kt,hkt,hkt1:string;
i,j:integer;
Begin
Writeln('*********Program Pembalik kata versi 1.0********');
Writeln(' ==============dede sii anak online===========');
Writeln;
Write('Masukkan Kata: ');Readln(kt);
Writeln;
j:=length(kt);
hkt:='';
For i:= 1 to j do
hkt:=hkt+kt[i];
For i:= j downto 1 do
hkt1:=hkt1+kt[i];
Writeln('Asal: ',hkt,' Dibalik: ',hkt1);
Writeln;
if (hkt=hkt1) then
Writeln('Kata Tersebut Termasuk Polindrom!')
else
Writeln('Kata Tersebut Tidak Termasuk Polindrom!');
End.

Output:



Readln(Ul);
Until Upcase(Ul)<>'Y';
End.
Program DataPegawai:

Uses Wincrt;
Type Pegawai = record
NIP : String[9];
Nama : String[30];
Golongan : Char;
Jamkerja : Real;
End;
Var
Data : Pegawai;
Gapok : Real;
Insentif,Gaber : Real;
Ul : Char;
Begin
Repeat
Clrscr;
Writeln(‘Data Pegawai Pt Wapp Sistem’);
Writeln('===========================');
Writeln;
Write('NIP : ');Readln(Data.NIP);
Write('Nama : ');Readln(Data.Nama);
Write('Golongan : ');Readln(Data.Golongan);
Write('Jam Kerja : ');Readln(Data.Jamkerja);
Writeln;
Writeln;
Case Data.Golongan of
'1' : Gapok:=1000000;
'2' : Gapok:=1500000;
'3' : Gapok:=2000000;
Else
Gapok:=0;
End;
if Data.Jamkerja>200 then
Insentif:=(Data.Jamkerja-200)*10000
else
Insentif:=0;
Gaber:=Gapok+Insentif;
Clrscr;
Writeln('Laporan Gaji Pegawai');
Writeln('PT. Wapp Sistem');
Writeln;
Writeln('============================================================================');
Writeln('|NIP         | Nama       | Golongan     | Jam Kerja         | Gaji        |');
Writeln('============================================================================');
Writeln('|',Data.NIP:10,'|',Data.Nama:25,'|',Data.Golongan:10,'|',Data.Jamkerja:11:0,'|',Gaber:14:2,'|');
Writeln('progam versi 1.0 by dede====================================================');
Writeln;
Write('Mau Ulang Lagi? [Y/T]: ');Readln(Ul);
Until Upcase(Ul)<>'Y';
End.

Output:

______________________________________________________________________________________________TUNGGU LATIHAN  SAYA SELANJUTNYA , :D

2 comments:

silahkan postkan komentar anda