Advertisement
Fundamentalen

QuadraticEquation

Mar 16th, 2014
439
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.         Console.Write("a = ");
  8.         double a = double.Parse(Console.ReadLine());
  9.         Console.Write("b = ");
  10.         double b = double.Parse(Console.ReadLine());
  11.         Console.Write("c = ");
  12.         double c = double.Parse(Console.ReadLine());
  13.  
  14.         double d = ((b * b) - (4 * a * c));
  15.         double x1 = ((-b - Math.Sqrt(d)) / (2 * a));
  16.         double x2 = ((-b + Math.Sqrt(d)) / (2 * a));
  17.  
  18.         if (d < 0)
  19.         {
  20.             Console.WriteLine("no real roots");
  21.         }
  22.         else if (x1 == x2)
  23.         {
  24.             Console.WriteLine("x1 = x2 = " + x1);
  25.         }
  26.         else
  27.         {
  28.             Console.WriteLine("x1 = " + x1);
  29.             Console.WriteLine("x2 = " + x2);
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement