Kombinasi IF THEN & WHILE DO
program Bangun_Ruang;
uses wincrt;
const
phi=3.14;
var
lagi:char;
p,l,t,a,r:real;
pilihan:byte;
luas:real;
begin
lagi:='Y';
while (lagi='Y') or (lagi='y') do
begin
writeln('Pilihan');
writeln('==========================');
writeln('1. Hitung Luas Lingkaran');
writeln('2. Hitung Luas Segitiga');
writeln('3. Hitung Luas Bujur Sangkar');
writeln('0. Selesai');
writeln('==========================');
writeln('');
write('Masukkan Angka Pilihan 1/2/3/0: ');readln(pilihan);
if pilihan=1 then
begin
clrscr;
writeln('');
writeln('Menghitung Luas lingkaran');
writeln('---------------------------');
write('Masukkan jari-jari / r : ');readln(r);
luas:=phi*r*r;
Write('Luas Lingkaran= ',luas:4:2);
readln(lagi);
end;
if pilihan=2 then
begin
clrscr;
writeln('');
writeln('Menghitung Luas Segitiga');
writeln('---------------------------');
write('Masukkan alas : ');readln(a);
write('Masukkan tinggi: ');readln(t);
luas:=1/2*a*t;
write('Luas Segitiga= ',luas:4:2);
readln(lagi);
end;
if pilihan=3 then
begin
clrscr;
writeln('');
writeln('Menghitung Luas Bujur Sangkar');
writeln('---------------------------');
write('Masukkan panjang : ');readln(p);
write('Masukkan lebar : ');readln(l);
luas:=p*l;
Write('Luas Bujur Sangkar= ',luas:4:2);
readln(lagi);
end;
if pilihan=0 then
begin
clrscr;
writeln('---Selesai---');
end;
clrscr;
writeln('');
write('Apakah mau mencoba lagi [Y/T]?');
readln(lagi);
end;
clrscr;
write('selesai ! ');
end.
Kombinasi ARRAY & FOR DO
Program nama_no;
Uses winCrt;
var
nama : Array[1..5] of string;
nilai : Array[1..5] of integer;
i,n:integer;
jum,rata:real;
Begin
write('Banyak Data : ');readln(n);
{---input---}
For i:= 1 to n Do
begin
write('Nama Mahasiswa : ');readln(nama[i]);
write('Nilai Mahasiswa : ');readln(nilai[i]);
writeln('------------------');
end;
writeln;
{---proses---}
jum:=0;
for i:=1 to n do
begin
jum:=jum+nilai[i];
rata:=jum/n;
end;
{---output---}
writeln('DATA NILAI MAHASISWA');
writeln('========================');
writeln('NAMA NILAI');
writeln('========================');
for i:=1 to n do
begin
writeln(nama[i],' ',nilai[i]);
end;
writeln('------------------');
writeln('jumlah nilai: ', jum:2:1);
writeln('rata-rata : ',rata:2:1);
End.
program Bangun_Ruang;
uses wincrt;
const
phi=3.14;
var
lagi:char;
p,l,t,a,r:real;
pilihan:byte;
luas:real;
begin
lagi:='Y';
while (lagi='Y') or (lagi='y') do
begin
writeln('Pilihan');
writeln('==========================');
writeln('1. Hitung Luas Lingkaran');
writeln('2. Hitung Luas Segitiga');
writeln('3. Hitung Luas Bujur Sangkar');
writeln('0. Selesai');
writeln('==========================');
writeln('');
write('Masukkan Angka Pilihan 1/2/3/0: ');readln(pilihan);
if pilihan=1 then
begin
clrscr;
writeln('');
writeln('Menghitung Luas lingkaran');
writeln('---------------------------');
write('Masukkan jari-jari / r : ');readln(r);
luas:=phi*r*r;
Write('Luas Lingkaran= ',luas:4:2);
readln(lagi);
end;
if pilihan=2 then
begin
clrscr;
writeln('');
writeln('Menghitung Luas Segitiga');
writeln('---------------------------');
write('Masukkan alas : ');readln(a);
write('Masukkan tinggi: ');readln(t);
luas:=1/2*a*t;
write('Luas Segitiga= ',luas:4:2);
readln(lagi);
end;
if pilihan=3 then
begin
clrscr;
writeln('');
writeln('Menghitung Luas Bujur Sangkar');
writeln('---------------------------');
write('Masukkan panjang : ');readln(p);
write('Masukkan lebar : ');readln(l);
luas:=p*l;
Write('Luas Bujur Sangkar= ',luas:4:2);
readln(lagi);
end;
if pilihan=0 then
begin
clrscr;
writeln('---Selesai---');
end;
clrscr;
writeln('');
write('Apakah mau mencoba lagi [Y/T]?');
readln(lagi);
end;
clrscr;
write('selesai ! ');
end.
Kombinasi ARRAY & FOR DO
Program nama_no;
Uses winCrt;
var
nama : Array[1..5] of string;
nilai : Array[1..5] of integer;
i,n:integer;
jum,rata:real;
Begin
write('Banyak Data : ');readln(n);
{---input---}
For i:= 1 to n Do
begin
write('Nama Mahasiswa : ');readln(nama[i]);
write('Nilai Mahasiswa : ');readln(nilai[i]);
writeln('------------------');
end;
writeln;
{---proses---}
jum:=0;
for i:=1 to n do
begin
jum:=jum+nilai[i];
rata:=jum/n;
end;
{---output---}
writeln('DATA NILAI MAHASISWA');
writeln('========================');
writeln('NAMA NILAI');
writeln('========================');
for i:=1 to n do
begin
writeln(nama[i],' ',nilai[i]);
end;
writeln('------------------');
writeln('jumlah nilai: ', jum:2:1);
writeln('rata-rata : ',rata:2:1);
End.
Komentar