Advertisement
diyanborisov

QuadraticEq

Nov 29th, 2015
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 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.  
  8. class QuadraticEq
  9. {
  10.     static void Main()
  11.     {  
  12.         double a = double.Parse(Console.ReadLine());
  13.         double b = double.Parse(Console.ReadLine());
  14.         double c = double.Parse(Console.ReadLine());
  15.         double determinant = Math.Pow(b, 2) - (4 * a * c);
  16.         if (determinant == 0)
  17.         {
  18.             Console.WriteLine("There is one real root x1=x2= "+ (-b/(2*a)));
  19.         }
  20.         else if ( determinant > 0)
  21.         {
  22.             double firstRoot = (-b - Math.Sqrt(determinant)) / (2 * a);
  23.             double secondRoot = (-b + Math.Sqrt(determinant)) / (2 * a);
  24.             Console.WriteLine("There is two real roots x1 = " + firstRoot + ", x2 = " + secondRoot );
  25.         }
  26.         else
  27.         {
  28.             Console.WriteLine("There is no real roots.");
  29.         }
  30.        
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement