Quadratic Equation

Easymath
XA
xaaduProblem Author

You are given the coefficients of a quadratic equation in the form:

ax2+bx+c=0ax^2 + bx + c = 0

where a0a \neq 0.

Your task is to determine if the equation has real roots and print them in ascending order if they exist. If the equation has no real roots, print "No real roots".

The roots of a quadratic equation are calculated using the quadratic formula:

x=b±b24ac2ax = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}

The discriminant Δ\Delta determines the nature of roots:

Δ=b24ac\Delta = b^2 - 4ac
  • If Δ>0\Delta > 0: Two distinct real roots exist
  • If Δ=0\Delta = 0: One real root exists (repeated root)
  • If Δ<0\Delta < 0: No real roots exist

Notes

  • Remember to handle the case where Δ=0\Delta = 0 separately (print only one root, not two identical roots)
  • Ensure roots are printed in ascending order
  • Use proper rounding to 2 decimal places

Input Format

  • Three integers: a, b, and c representing the coefficients of the quadratic equation
  • Input is given as three space-separated integers
  • a0a \neq 0 is guaranteed

Output Format

  • If two distinct real roots exist, print them on a single line separated by a space in ascending order, rounded to 2 decimal places
  • If one real root exists (repeated), print that single root rounded to 2 decimal places
  • If no real roots exist, print No real roots

Constraints

  • 1000a,b,c1000-1000 \leq a, b, c \leq 1000
  • a0a \neq 0
  • All test cases will have solutions that fit within standard floating-point precision

Sample Test Cases

Test Case 1

Input:
1 -3 2
Output:
1.00 2.00
Explanation:

For the equation x23x+2=0x^2 - 3x + 2 = 0:

  • Discriminant: Δ=(3)24(1)(2)=98=1\Delta = (-3)^2 - 4(1)(2) = 9 - 8 = 1
  • Since Δ>0\Delta > 0, two distinct real roots exist
  • Root 1: x1=312=312=1.00x_1 = \frac{3 - \sqrt{1}}{2} = \frac{3 - 1}{2} = 1.00
  • Root 2: x2=3+12=3+12=2.00x_2 = \frac{3 + \sqrt{1}}{2} = \frac{3 + 1}{2} = 2.00

Test Case 2

Input:
1 -4 4
Output:
2.00
Explanation:

For the equation x24x+4=0x^2 - 4x + 4 = 0:

  • Discriminant: Δ=(4)24(1)(4)=1616=0\Delta = (-4)^2 - 4(1)(4) = 16 - 16 = 0
  • Since Δ=0\Delta = 0, one repeated real root exists
  • Root: x=42=2.00x = \frac{4}{2} = 2.00

Code Editor

Login to submit your solution

Output

Test results will appear here...