Contoh Program Rekursif pada pascal
uses crt;
function kali(a,b:integer):longint;
begin
if b>1 then
begin
kali:= kali(a,b-1)+a;
end else
kali:=a;
end;
procedure Volume;
var a,b,c:integer;
v:real;
begin clrscr;
write('Panjang Limas : '); readln(a);
write('Lebar Limas : '); readln(b);
write('Tinggi Limas : '); readln(c);
v:=1/3*kali(a,b)*c;
writeln('Volume Limas : ',v:2:0); readln;
end;
procedure Luas;
var a,b,c :integer;
l :real;
begin
clrscr;
write('Panjang Limas : '); readln(a);
write('Lebar Limas : '); readln(b);
write('Tinggi Limas : '); readln(c);
l:=kali(a,b)+1/2*kali(b,c)*4;
writeln('Luas Limas : ',l:2:0); readln;
end;
var Pilih : char;
begin
repeat
clrscr;
writeln(' 1. Volume Limas Segi Empat');
writeln(' 2. Luas Limas Segi Empat');
writeln(' 3. Keluar');
writeln;
write('Pilih : ');readln(Pilih);
case Pilih of
'1' : Volume;
'2' : Luas;
'3' : exit;
end;
until Pilih = '3';
end.
0 komentar:
Posting Komentar