Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class QuadraticEquation
- {
- static void Main()
- {
- Console.Write("Enter 'a': ");
- double a = double.Parse(Console.ReadLine());
- Console.Write("Enter 'b': ");
- double b = double.Parse(Console.ReadLine());
- Console.Write("Enter 'c': ");
- double c = double.Parse(Console.ReadLine());
- double discriminant = Math.Pow(b, 2) - (4 * a * c);
- double x1;
- double x2;
- if (a == 0)
- {
- Console.WriteLine("'a' must not be '0'");
- }
- else if (discriminant > 0 && a != 0)
- {
- x1 = ((-b) - (Math.Sqrt(discriminant))) / (2 * a);
- x2 = ((-b) + (Math.Sqrt(discriminant))) / (2 * a);
- Console.WriteLine("x1 = {0}; x2 = {1}", x1, x2);
- }
- else if (discriminant == 0 && a != 0)
- {
- x1 = x2 = -(b / (2 * a));
- Console.WriteLine("x1 = x2 = {0}", x1);
- }
- else
- {
- Console.WriteLine("no real roots");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement