PROGRAM PERSAMAAN KUADRAT MENGGUNAKAN FUNCTION
program fungsi_kuadrat;
uses wincrt;
var
a,b,c: integer;
function diskriminan(var a,b,c:integer):integer;
begin
diskriminan := (b*b)-(4*a*c);
end;
function x1(var a,b,c : integer):real;
begin
x1 := (-b+(sqrt(diskriminan(a,b,c))))/(2*a);
end;
function x2(var a,b,c : integer):real;
begin
x2 := (-b-(sqrt(diskriminan(a,b,c))))/(2*a);
end;
begin
write('masukkan nilai a: '); readln(a);
write('masukkan nilai b: '); readln(b);
write('masukkan nilai c: '); readln(c);
if diskriminan(a,b,c) < 0 then
begin
write('diskriminan kurang dari 0');
end
else
begin
writeln('x1 : ', x1(a,b,c):0:2);
writeln('x2 : ', x2(a,b,c):0:2);
end;
end.
Running program:
0 komentar:
Post a Comment