Title: compile a program, the input values a, b, c, and obtains a quadratic equation a * x * x + b * x + c = 0 the two real roots.
My thoughts:
We all know that in seeking a quadratic equation mathematics there are many ways: directly open method, with method, formula, factorization method, etc., where I chose the formula method:
First determine this quadratic equation has no solution, a discriminant ▲ greater than 0 has two real roots, equal to 0 there is a real number of the less than 0 no real roots
re-used unitary the quadratic equation obtained Root values, specific code as follows:
// value Console.WriteLine ( " Enter a value of: " ); int a = int .Parse (Console.ReadLine ()); Console.WriteLine ( " Please enter the value of b: " ); int b = int .Parse (Console.ReadLine ()); Console.WriteLine ( " enter a value of c: " ); int c = int .Parse (Console.ReadLine ()); // calculate root Double X1, X2; IF (B B * - . 4 * A * C> 0 ) { X1 = (-b + Math.Sqrt (B * B - . 4 * A * C)) / 2 * A; X2 = (-b - Math.Sqrt (B * B - . 4 * A * C)) / 2 * a; Console.WriteLine ( " a quadratic equation {0} * x * x + {1} * x + {root} 2 = 0 is: {}. 3 \ {T}. 4 " , a, B, C, X1 , X2); } the else IF (B * B - . 4 * A * C == 0 ) { X1 = (-b + Math.Sqrt (B * B - . 4 * A * C)) / 2 * A; Console.WriteLine ( " a quadratic equation {0} * x * x + {1} * x + {root} 2 = 0 is: {}. 3 " , A, B, C, X1); } the else { Console.WriteLine ( " a quadratic equation {0} * x * x + {1} * x + {2} = 0 no solution! " , a, B, C); } Console.ReadLine ();