Roots of a quadratic equation
You are given cofficients
a, b and c of a quadratic equation ax2 + bx + c = 0. Find the roots r1, r2 of the equation.
Note:
r1 and r2 should be rounded upto 2 decimal places.
Input
The first line of input is an integer
a. The second line of input is an integer b. The third line of input is an integer c.
Explanation
In the given example, a = 1, b = -5, c = 6. Then the equation is x2 - 5x + 6 = 0
r1 = (-b + (b^2 - 4*a*c)^0.5)/2*a
r1 = (5 + (25 - 24))/2
r1 = 3
and
r2 = (-b - (b^2 - 4*a*c)^0.5)/2*a
r2 = (5 - (25 - 24))/2
r2 = 2
So, the output should be
3
2
Sample Input 1
1
-5
6
Sample Output 1
3.0
2.0
Sample Input 2
-1
1
6
Sample Output 2
-2.0
3.0
Comments
Leave a comment