← Back to If Statements
Question 249
Quadratic Roots
Quadratic Roots
Three numbers a, b and c are the coefficients of the equation a·x² + b·x + c = 0 (a is not zero). Compute the discriminant b² − 4ac. When it is positive printTwo real roots: <r1> and <r2>with the larger root first; when it is zero printOne real root: <r>; when it is negative printNo real roots. UseMath.sqrtfor the square root and the usual formula (−b ± √d) / (2a).
Expected Output:
Two real roots: 2 and 1= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
If Statements
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (clog, fn, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.