Contoh-Contoh Prgram Pascal Sederhana
1. Program Konversi Suhuuses crt;
var
celcius, fahrenheit, reamur, hasil : real;
begin
clrscr;
writeln ('Program Konversi Suhu');
writeln ('================');
writeln;
write ('Masukkan Suhu Celcius = ');
readln (celcius);
fahrenheit := (9/5 * celcius) + 32;
reamur := 4/5 * celcius;
writeln ('Berikut Hasilnya = ', fahrenheit:4:2, ' F');
writeln (' = ', reamur:4:2, ' R');
readln;
end.
2. Program Volume Balok
uses crt;
var
panjang, lebar, tinggi : real;
volume : real;
begin
clrscr;
writeln ('Program Volume Balok');
writeln;
writeln ('Masukkan Data');
write ('Panjang cm = ');
readln (panjang);
write ('Lebar cm = ');
readln (lebar);
write ('Tinggi cm = ');
readln (tinggi);
volume := panjang * lebar * tinggi;
writeln;
writeln ('Hasil Volume = ', volume:4:2, ' cm^3');
readln;
end.
3. Program Menghitung Luas dan Keliling Persegi Panjang
uses crt;var
panjang, lebar : integer;
luas, keliling : integer;
begin
clrscr;
writeln ('Program Menghitung Luas Keliling Persegi Panjang');
writeln;
write ('Panjang = ');
readln (panjang);
write ('Lebar = ');
readln (lebar);
luas := panjang * lebar;
keliling := 2 * (panjang * lebar);
writeln;
writeln ('Luas = ', luas);
writeln ('Keliling = ', keliling);
readln;
end.
oleh : Pomo Heri S
0 comments: