Advertisement
iliqnvidenov

quadratic equation

Nov 28th, 2014
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.81 KB | None | 0 0
  1. using System;
  2.  
  3.  
  4.  
  5. class Program
  6. {
  7.     static void Main()
  8.     {
  9.         double a, b, c;
  10.         a = double.Parse(Console.ReadLine());
  11.         b = double.Parse(Console.ReadLine());
  12.         c = double.Parse(Console.ReadLine());
  13.         double D = b * b - 4 * a * c;
  14.             double x, x1, x2;
  15.             if (D > 0)
  16.             {
  17.                 x2 = (-b + System.Math.Sqrt(D)) / (2 * a);
  18.                 x1 = (-b - System.Math.Sqrt(D)) / (2 * a);
  19.                 Console.WriteLine("x1={0}; x2={1}", x1, x2);
  20.             }
  21.             else if (D < 0)
  22.             {
  23.                 Console.WriteLine("no real roots");
  24.             }
  25.             else
  26.             {
  27.                 x = (-b + System.Math.Sqrt(D)) / (2 * a);
  28.                 Console.WriteLine("x1=x2={0}", x);
  29.             }
  30.         }
  31.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement