Quadratic equation in Algol68
Example for versions
Algol68g-1.18.0
A direct translation of the C++ example.
PROC print root = (INT ind, LONG COMPL x)VOID:
( print(("x", ind, " := "));
IF ABS(im OF x) < 1E-6 THEN
print((re OF x, new line))
ELSE print((x, new line))
FI
);
main:
( LONG COMPL a, b, c, d, x1, x2;
print(("a := "));
read((a));
IF ABS a <1E-3 THEN
print(( "Not a quadratic equation", new line));
stop
FI;
print(("b := "));
read((b));
print(("c := "));
read((c));
a *:= 2;
d := b*b-a*c*2.0;
IF ABS d <1E-3 THEN
print(("x := ", re OF (-b/a)))
ELSE
print root(1, (-b+long complex sqrt(d))/a);
print root(2, (-b-long complex sqrt(d))/a)
FI
)
Comments
]]>blog comments powered by Disqus
]]>