Roots of a quadratic function: Difference between revisions

Content added Content deleted
mNo edit summary
Line 816: Line 816:
procedure solve(a,b,c)
procedure solve(a,b,c)
d := sqrt(b*b - 4.0*a*c)
d := sqrt(b*b - 4.0*a*c)
roots := if b < 0 then [r1 := (-b+d)/2.0*a, c/(a*r1)]
roots := if b < 0 then [r1 := (-b+d)/(2.0*a), c/(a*r1)]
else [r1 := (-b-d)/2.0*a, c/(a*r1)]
else [r1 := (-b-d)/(2.0*a), c/(a*r1)]
write(a,"*x^2 + ",b,"*x + ",c," has roots ",roots[1]," and ",roots[2])
write(a,"*x^2 + ",b,"*x + ",c," has roots ",roots[1]," and ",roots[2])
end</lang>
end</lang>