Quadratic Equation
Easymath
XA
xaaduProblem Author
You are given the coefficients of a quadratic equation in the form:
where .
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:
The discriminant determines the nature of roots:
- If : Two distinct real roots exist
- If : One real root exists (repeated root)
- If : No real roots exist
Notes
- Remember to handle the case where 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, andcrepresenting the coefficients of the quadratic equation - Input is given as three space-separated integers
- 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
- 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 :
- Discriminant:
- Since , two distinct real roots exist
- Root 1:
- Root 2:
Test Case 2
Input:
1 -4 4
Output:
2.00
Explanation:
For the equation :
- Discriminant:
- Since , one repeated real root exists
- Root:
Code Editor
Login to submit your solution
Output
Test results will appear here...