hAleksandrova

QuadraticEquation

Oct 25th, 2012
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6.  
  7.  
  8. class QuadraticEquation
  9. {
  10. static void Main(string[] args)
  11. {
  12. double a, b, c, d, x, x1, x2;
  13. Console.Write("a= ");
  14. a = double.Parse(Console.ReadLine());
  15. Console.Write("b= ");
  16. b = double.Parse(Console.ReadLine());
  17. Console.Write("c= ");
  18. c = double.Parse(Console.ReadLine());
  19. d = b * b - (4 * a * c);
  20. x = -b / (2 * a);
  21. x1 = (-b - Math.Sqrt(d)) / (2 * a);
  22. x2 = (-b + Math.Sqrt(d)) / (2 * a);
  23. if (a == 0)
  24. {
  25. Console.WriteLine("The equation is not square!");
  26. }
  27. else if (d < 0)
  28. {
  29. Console.WriteLine("Тhe equation has no real roots! D = " + d);
  30. }
  31. else if (d == 0)
  32. {
  33.  
  34. Console.WriteLine("D = 0, x = " + x);
  35. }
  36.  
  37.  
  38. else if (d > 0)
  39. {
  40.  
  41. Console.WriteLine("D = " + d + " " + "x1 = " + x1 + " " + "x2 = " + x2);
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment