Advertisement
remote87

QuadraticEquation

Aug 22nd, 2015
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.23 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _06.QuadraticEquation
  8. {
  9.     class QuadraticEquation
  10.     {
  11.         static void Main()
  12.         {
  13.             Console.Write("Enter first number: ");
  14.             double a = double.Parse(Console.ReadLine());
  15.             Console.Write("Enter second number: ");
  16.             double b = double.Parse(Console.ReadLine());
  17.             Console.Write("Enter third number: ");
  18.             double c = double.Parse(Console.ReadLine());
  19.             double discriminant = (b * b) - (4 * a * c);
  20.             if (discriminant > 0)
  21.             {
  22.                 double x1 = ((-b) - Math.Sqrt(discriminant)) / (2 * a);
  23.                 double x2 = ((-b) + Math.Sqrt(discriminant)) / (2 * a);
  24.                 Console.WriteLine("x1 = {0} ; x2 = {1}", x1, x2);
  25.             }
  26.             else if (discriminant == 0)
  27.             {
  28.                 double x1Andx2 = ((-b) + Math.Sqrt(discriminant)) / (2 * a);
  29.                 Console.WriteLine("x1 = x2 = {0}", x1Andx2);
  30.             }
  31.             else if (discriminant < 0)
  32.             {
  33.                 Console.WriteLine("No real roots.");
  34.             }
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement