Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace QuadraticEquation
- {
- class Program
- {
- static void Main(string[] args)
- {
- double a = double.Parse(Console.ReadLine());
- double b = double.Parse(Console.ReadLine());
- double c = double.Parse(Console.ReadLine());
- double discriminant = (b * b) - (4 * a * c);
- double x1 = 0;
- double x2 = 0;
- if (discriminant > 0)
- {
- x1 = ((-b) - Math.Sqrt(discriminant)) / (2 * a);
- x2 = ((-b) + Math.Sqrt(discriminant)) / (2 * a);
- Console.WriteLine($"x1={x1}; x2={x2}");
- }
- else if (discriminant == 0)
- {
- x2 = ((-b) + Math.Sqrt(discriminant)) / (2 * a);
- x1 = x2;
- Console.WriteLine($"x1={x1}; x2={x2}");
- }
- else
- {
- Console.WriteLine("No real roots");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment