Advertisement
Martichka

Console Input Output Task 6

Dec 1st, 2012
56
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. class CuadraticEquision
  3. {
  4.     static void Main()
  5.     {
  6.         int a = int.Parse(Console.ReadLine());
  7.         int b = int.Parse(Console.ReadLine());
  8.         int c = int.Parse(Console.ReadLine());
  9.         double d = b*b - (4 * a * c);
  10.         double x1, x2;
  11.         if ((d > 0 ) && (a != 0))
  12.         {
  13.             x1 = ((-b) + Math.Sqrt(d)) / 2*a;
  14.             x2 =((-b) - Math.Sqrt(d)) / 2 *a;
  15.             Console.WriteLine("the equision has two roots: {0} and {1}.", x1, x2);
  16.         }
  17.  
  18.         else if((a == 0) || (d < 0))
  19.         {
  20.             Console.WriteLine("This is not a quadratic equision or the equision has no real roots!");
  21.         }
  22.  
  23.         else if (d == 0)
  24.         {
  25.             Console.WriteLine("This equision has one root: x = {0}.",(-b)/(2*a));
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement