Program to find the Roots of Quadratic equation | Prints roots of quadratic equation ax * 2 + bx + x ; If a is 0 , then equation is not quadratic , but linear ; else d < 0 ; Driver Code ; Function call
function findRoots ( a , b , c ) { if ( a == 0 ) { document . write ( " " ) ; return ; } let d = b * b - 4 * a * c ; let sqrt_val = Math . sqrt ( Math . abs ( d ) ) ; if ( d > 0 ) { document . write ( " " + " " ) ; document . write ( ( - b + sqrt_val ) / ( 2 * a ) + " " + ( - b - sqrt_val ) / ( 2 * a ) ) ; } else if ( d == 0 ) { document . write ( " " + " " ) ; document . write ( - b / ( 2 * a ) + " " + - b / ( 2 * a ) ) ; } { document . write ( " " ) ; document . write ( - b / ( 2 * a ) + " " + sqrt_val + " " + - b / ( 2 * a ) + " " + sqrt_val ) ; } } let a = 1 , b = - 7 , c = 12 ; findRoots ( a , b , c ) ;