Advertisement
Guest User

Quadratic

a guest
Apr 12th, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.80 KB | None | 0 0
  1. using System;
  2.  
  3. class QuadraticEquation
  4. {
  5.     static void Main()
  6.     {
  7.         double a = double.Parse(Console.ReadLine());
  8.         double b = double.Parse(Console.ReadLine());
  9.         double c = double.Parse(Console.ReadLine());
  10.  
  11.         double D = (Math.Pow(b, 2)) - 4 * a * c;
  12.  
  13.         if (D < 0)
  14.         {
  15.             Console.WriteLine("no real roots");
  16.             return;
  17.         }
  18.  
  19.         double sqrtD = Math.Sqrt(D);
  20.  
  21.         double x1 = ((-b) + sqrtD) / (2 * a);
  22.         double x2 = ((-b) - sqrtD) / (2 * a);
  23.  
  24.         if (x1 == x2)
  25.         {
  26.             Console.WriteLine("{0:0.00}", Math.Abs(x1));
  27.         }
  28.  
  29.         else
  30.         {
  31.             Console.WriteLine("{0:0.00}", Math.Min(x1, x2));
  32.             Console.WriteLine("{0:0.00}", Math.Max(x1, x2));
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement