Advertisement
KristianIvanov00

Quadratic Equation

Sep 30th, 2020
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. using System;
  2.  
  3. namespace QuadraticEquation
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. Console.Write("A = ");
  10. int a = int.Parse(Console.ReadLine());
  11. Console.Write("B = ");
  12. int b = int.Parse(Console.ReadLine());
  13. Console.Write("C = ");
  14. int c = int.Parse(Console.ReadLine());
  15. double d = b * b - 4 * a * c;
  16. double x1, x2;
  17. if (a == 0)
  18. {
  19. if (b == 0 && c == 0)
  20. {
  21. Console.WriteLine("All real numbers are solutions!");
  22. }
  23. else if (b == 0 && c != 0)
  24. {
  25. Console.WriteLine("There aren't real roots!");
  26. }
  27. else
  28. {
  29. x1 = x2 = -c / b;
  30. Console.Write("x = ");
  31. Console.WriteLine(x1);
  32. }
  33. }
  34. else
  35. {
  36. if (d < 0)
  37. {
  38. Console.WriteLine("There aren't real roots!");
  39. }
  40. else if (d == 0)
  41. {
  42. x1 = x2 = -b / 2 * a;
  43. Console.Write("x1 = x2 = ");
  44. Console.WriteLine(x1);
  45. }
  46. else
  47. {
  48. x1 = (-b + Math.Sqrt(d)) / (2 * a);
  49. x2 = (-b - Math.Sqrt(d)) / (2 * a);
  50. Console.Write("x1 = ");
  51. Console.WriteLine(x1);
  52. Console.Write("x2 = ");
  53. Console.WriteLine(x2);
  54. }
  55. }
  56. }
  57. }
  58. }
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement