Phoenix_x

Untitled

Oct 10th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.20 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Example
  4. {
  5.     class Program
  6.     {
  7.         static void Main()
  8.         {
  9.             double a = double.Parse(Console.ReadLine());
  10.             double b = double.Parse(Console.ReadLine());
  11.             double c = double.Parse(Console.ReadLine());
  12.  
  13.  
  14.             if (a > 0)
  15.             {
  16.                 double x1 = 0;
  17.                 double x2 = 0;
  18.                 double discriminant = b * b - 4 * (a * c);
  19.  
  20.                 if (discriminant > 0)
  21.                 {
  22.                     x1 = ((-b) - Math.Sqrt(discriminant)) / 2 * a;
  23.                     x2 = ((-b) + Math.Sqrt(discriminant)) / 2 * a;
  24.                     Console.WriteLine($"X1 = {x1}");
  25.                     Console.WriteLine($"X2 = {x2}");
  26.                 }
  27.  
  28.                 else if (discriminant == 0)
  29.                 {
  30.                     x1 = (-b) / 2 * a;
  31.                     Console.WriteLine($"X1 = {x1}");
  32.                 }
  33.  
  34.                 else
  35.                 {
  36.                     Console.WriteLine("No real roots!");
  37.                 }
  38.             }
  39.  
  40.             else
  41.             {
  42.                 Console.WriteLine("Queficent a should be bigger than zero.");
  43.             }
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment