Contoh 1:
program prosedur_dengan_parameter_byreference;
uses wincrt;
procedure perkalian(var a,b,c:real);
begin
c:=a*b;
end;
{program utama}
var x,y,z :real;
begin
clrscr;
x:=5.0;
y:=10.0;
z:=9.0;
writeln ('x =
',x:4:2);
writeln('y =
',y:4:2);
writeln('z =
',z:4:2);
perkalian(x,y,z);
writeln('x * z =
',z:4:2);
readln;
end.
Contoh 2 :
program fungsi_dengan_parameter_byyvalue;
uses wincrt;
function perkalian(a,b,c:real):real;
begin
perkalian:=a*b;
c:=a/b;
end;
{program utama}
var x,y,z :real;
begin
clrscr;
x:=5.0;
y:=10.0;
z:=9.0;
writeln('x =
',x:4:2);
writeln('y =
',y:4:2);
writeln('z =
',z:4:2);
writeln(' x y z =
',perkalian(x,y,z):4:2);
writeln('nilai z
setelah fungsi dijalankan : ');
writeln('z =
',z:4:2);
readln;
end.
Tidak ada komentar:
Posting Komentar
Semoga Bermanfaat