Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Numerics;
- class GeneralizedQuadraticEquation
- {
- static void Main()
- {
- Console.WriteLine("This program solves general (non-real roots included) quadratic equations of the form ax^2 + bx + c = 0");
- Console.Write("Please enter coefficient a: ");
- double a = double.Parse(Console.ReadLine());
- Console.Write("Please enter coefficient b: ");
- double b = double.Parse(Console.ReadLine());
- Console.Write("Please enter coefficient c: ");
- double c = double.Parse(Console.ReadLine());
- double discriminant = b * b - 4 * a * c; //calculations start here
- Complex squarerootDiscriminant = Complex.Sqrt(discriminant);
- if (discriminant == 0)
- {
- double x = -b / 2 / a;
- Console.WriteLine("Double root x1 = x2 = {0}", x);
- }
- else
- {
- Complex x1 = (-b - squarerootDiscriminant) / 2 / a;
- Complex x2 = (-b + squarerootDiscriminant) / 2 / a;
- Console.WriteLine("The solution of the equation is : x1 = {0}, \r\n x2 = {1}", x1, x2);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement