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 ; d < 0 ; Driver code ; Function call
< ? php function findRoots ( $ a , $ b , $ c ) { if ( $ a == 0 ) { echo " Invalid " ; return ; } $ d = $ b * $ b - 4 * $ a * $ c ; $ sqrt_val = sqrt ( abs ( $ d ) ) ; if ( $ d > 0 ) { echo " Roots ▁ are ▁ real ▁ and ▁ " . " different ▁ STRNEWLINE " ; echo ( - $ b + $ sqrt_val ) / ( 2 * $ a ) , " STRNEWLINE " , ( - $ b - $ sqrt_val ) / ( 2 * $ a ) ; } else if ( $ d == 0 ) { echo " Roots ▁ are ▁ real ▁ and ▁ same ▁ STRNEWLINE " ; echo - $ b / ( 2 * $ a ) ; } else { echo " Roots ▁ are ▁ complex ▁ STRNEWLINE " ; echo - $ b / ( 2 * $ a ) , " ▁ + ▁ i " , $ sqrt_val , " STRNEWLINE " , - $ b / ( 2 * $ a ) , " ▁ - ▁ i " , $ sqrt_val ; } } $ a = 1 ; $ b = -7 ; $ c = 12 ; findRoots ( $ a , $ b , $ c ) ; ? >