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