BSO90

Quadratic Equation

Apr 27th, 2021
775
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.08 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Problem_5._Quadratic_Equation
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             double firstCoefficient = double.Parse(Console.ReadLine());
  10.             double secondCoefficient =double.Parse(Console.ReadLine());
  11.             double thirdCoefficient = double.Parse(Console.ReadLine());
  12.             double discriminant = Math.Pow(secondCoefficient, 2) - 4 * firstCoefficient * thirdCoefficient;
  13.             double root1 = 0;
  14.             double root2 = 0;
  15.             if (discriminant == 0)
  16.             {
  17.                 root1 = -(secondCoefficient / (2 * firstCoefficient));
  18.                 Console.WriteLine($"x1={root1};x2={root1}");
  19.             }
  20.             else
  21.             {
  22.                 root1 = -(secondCoefficient + Math.Sqrt(discriminant)) / (2 * firstCoefficient);
  23.                 root2 = -(secondCoefficient - Math.Sqrt(discriminant)) / (2 * firstCoefficient);
  24.                 Console.WriteLine($"x1={root1};x2={root2}");
  25.             }
  26.         }
  27.     }
  28. }
  29.              
  30.                
  31.  
  32.            
  33.  
  34.  
Advertisement
Add Comment
Please, Sign In to add comment