Kumpulan program pascal ini merupakan kumpulan latihan saat saya belajar bahasa
pemrograman pascal. Penulis menggunakan Turbo Pascal for Windows (TPW) Versi
1.5 sebagai kompilernya. Mungkin ada kekurangan disana sini, tapi mudah-mudahan
kumpulan program ini bermanfaat bagi pembaca yang berminat dan baru mempelajari
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('======================================');
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.
Program Konversi_Suhu;
Uses WinCrt;
var f,c:real;
begin
Writeln('Program Konversi Fareinheit Ke Celcius');
Writeln('======================================');
Writeln;
Write('Masukan Suhu dalam Farenheit: ');readln(f);
c:=5/9*(f-32);
Writeln;
Writeln('Jadi Suhu Dalam Celcius Adalah: ',c:4:2);
end.
Program Konversi_Waktu;
Uses Wincrt;
Var j,m,d,h:integer;
begin
Writeln('Program Konversi Waktu');
Writeln('======================');
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');
end.
Program Konversi_Waktu1;
Uses WinCrt;
var j,m,d,dm,sisa,sisa1:integer;
begin
Writeln('Program Konversi Waktu 1');
Writeln('========================');
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');
end.
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('================================');
Writeln;
Write('Waktu ke-1 jam : ');readln(j);
Write('Waktu ke-1 Menit : ');readln(m);
Write('Waktu ke-1 Detik : ');readln(d);
Writeln('================================');
Write('Waktu ke-2 jam : ');readln(j1);
Write('Waktu ke-2 Menit : ');readln(m1);
Write('Waktu ke-2 Detik : ');readln(d1);
h:=(j*3600)+(m*60)+d;
h1:=(j1*3600)+(m1*60)+d1;
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');
End.
Program Menukar_Nilai;
Uses WinCrt;
var A,B,C:integer;
Begin
Writeln('Program Menukar Nilai A Menjadi B');
Writeln('=================================');
Writeln;
Write('Masukkan Nilai A: ');readln(A);
Write('Masukkan Nilai B: ');readln(B);
Writeln;
C:=A;
A:=B;
B:=C;
Writeln;
Writeln('Hasil A=',A,' B=',B);
End.
Program Menukar_Nilai1;
Uses WinCrt;
var A,B:integer;
Begin
Writeln('Program Menukar Nilai A Menjadi B');
Writeln('=================================');
Writeln;
Write('Masukkan Nilai A: ');readln(A);
Write('Masukkan Nilai B: ');readln(B);
Writeln;
A:=A-B;
B:=B+A;
A:=B-A;
Writeln;
Writeln('Hasil A=',A,' B=',B);
End.
Program Urut_Bilangan;
Uses Wincrt;
Var A,B,C:integer;
Begin
Writeln('Program Mengurut Bilangan');
Writeln('=========================');
Writeln;
Write('Masukkan Nilai A: ');readln(A);
Write('Masukkan Nilai B: ');readln(B);
Write('Masukkan Nilai C: ');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.
Program Menentukan_Segitiga;
Uses Wincrt;
Var A,B,C,X,Y:integer;
Begin
Writeln('Program Menentukan Segitiga');
Writeln('=========================');
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<Y) then
Writeln('Segitiga Lancip')
else if (X=Y) then
Writeln('Segitiga Siku-Siku')
else
Writeln('Segitiga Tumpul')
End.
Program Persamaan_Kuadrat;
Uses Wincrt;
Var A,B,C:integer;
D,X1,X2:real;
Begin
Writeln('Program Persamaan Kuadrat');
Writeln('=========================');
Writeln;
Write('Masukkan Nilai A: ');readln(A);
Write('Masukkan Nilai B: ');readln(B);
Write('Masukkan Nilai C: ');readln(C);
Writeln;
D:=sqr(B)-(4*A*C);
if (D>0) then
begin
X1:=(-B+sqrt(D))/2*A;
X2:=(-B-sqrt(D))/2*A;
Writeln('X1= ',X1:4:1,' ','X2= ',X2:4:1);
end
else if (D=0) then
begin
X1:=-B/(2*A);
Writeln('X1=X2=',X1:4:1);
end
else
Writeln('Akar Imajiner!');
End.
Program Faktorial;
Uses Wincrt;
Var i,n,x:integer;
Begin
Writeln('Program Faktorial');
Writeln('=================');
Writeln;
Write('Masukkan Nilai Faktorial: ');Readln(n);
Writeln;
if (n<=0) then
Writeln('Hasil Faktorial: ',1)
else
Begin
x:=1;
For i := 1 to n do
x:=x*i;
Writeln('Hasil Faktorial: ',x);
End;
End.
Program Menghitung_Rata_Rata;
Uses Wincrt;
Var n,x,i,tot:integer;
rata:real;
Begin
Writeln('Program Menghitung Rata-Rata');
Writeln('============================');
Writeln;
Write('Masukkan Jumlah Bilangan: ');readln(n);
Writeln;
Writeln('Masukkan Bilangan: ');
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);
End.
Program Menghitung_Pangkat;
Uses Wincrt;
Var i,n,m: integer;
x: real;
Begin
Writeln('Program Menghitung Pangkat');
Writeln('==========================');
Writeln;
Write('Masukkan Jumlah Pangkat : ');readln(n);
Write('Masukkan Bil. Yang DiPangkat : ');readln(m);
Writeln;
x:=1;
if (n>0) then
For i:= 1 to n do
x:=x*m
else if (n=0) then
x:=1
else
begin
n:=-1*n;
For i:= 1 to n do
begin
x:=x*(1/m);
end;
end;
Writeln('Hasil Pangkat: ',x:6:2);
End.
0 komentar:
Posting Komentar