Program to find the Roots of Quadratic equation | C # program to find roots of a 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
using System ; class Quadratic { void findRoots ( int a , int b , int c ) { if ( a == 0 ) { Console . Write ( " Invalid " ) ; return ; } int d = b * b - 4 * a * c ; double sqrt_val = Math . Abs ( d ) ; if ( d > 0 ) { Console . Write ( " Roots ▁ are ▁ real ▁ and ▁ different ▁ STRNEWLINE " ) ; Console . Write ( ( double ) ( - b + sqrt_val ) / ( 2 * a ) + " STRNEWLINE " + ( double ) ( - b - sqrt_val ) / ( 2 * a ) ) ; } else { Console . Write ( " Roots ▁ are ▁ complex ▁ STRNEWLINE " ) ; Console . Write ( - ( double ) b / ( 2 * a ) + " ▁ + ▁ i " + sqrt_val + " STRNEWLINE " + - ( double ) b / ( 2 * a ) + " ▁ - ▁ i " + sqrt_val ) ; } } public static void Main ( ) { Quadratic obj = new Quadratic ( ) ; int a = 1 , b = - 7 , c = 12 ; obj . findRoots ( a , b , c ) ; } }