Advertisement
tockata

Console Input/Output - Problem 6.

Mar 21st, 2014
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.26 KB | None | 0 0
  1. using System;
  2.  
  3.     class QuadraticEquation
  4.     {
  5.         static void Main()
  6.         {
  7.             Console.Write("Enter a: ");
  8.             int a = int.Parse(Console.ReadLine());
  9.             Console.Write("Enter b: ");
  10.             int b = int.Parse(Console.ReadLine());
  11.             Console.Write("Enter c: ");
  12.             int c = int.Parse(Console.ReadLine());
  13.             double d = (b * b) - (4 * a * c);
  14.  
  15.             if (d >= 0)
  16.             {
  17.                 if (d == 0)
  18.                 {
  19.                     Console.WriteLine("The quadratic equation with coefficients a={0}, b={1} and c={2} has one root:", a, b, c);
  20.                     Console.WriteLine("x= {0}", (-b/(2*a)));
  21.                 }
  22.                 else
  23.                 {
  24.                     Console.WriteLine("The quadratic equation with coefficients a={0}, b={1} and c={2} has the following roots:", a, b, c);
  25.                     Console.WriteLine("x1= {0}", ((-b+(Math.Sqrt(d)))/(2*a)));
  26.                     Console.WriteLine("x2= {0}", ((-b-(Math.Sqrt(d)))/(2*a)));
  27.                 }
  28.             }
  29.             else
  30.             {
  31.                 Console.WriteLine("The quadratic equation with coefficients a={0}, b={1} and c={2} has NO roots:", a, b, c);
  32.             }
  33.         }
  34.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement