nassss

Untitled

Oct 27th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. using System;
  2.  
  3. namespace QuadraticEquation
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. double a = double.Parse(Console.ReadLine());
  10. double b = double.Parse(Console.ReadLine());
  11. double c = double.Parse(Console.ReadLine());
  12.  
  13. double discriminant = (b * b) - (4 * a * c);
  14. double x1 = 0;
  15. double x2 = 0;
  16.  
  17. if (discriminant > 0)
  18. {
  19. x1 = ((-b) - Math.Sqrt(discriminant)) / (2 * a);
  20. x2 = ((-b) + Math.Sqrt(discriminant)) / (2 * a);
  21. Console.WriteLine($"x1={x1}; x2={x2}");
  22. }
  23. else if (discriminant == 0)
  24. {
  25. x2 = ((-b) + Math.Sqrt(discriminant)) / (2 * a);
  26. x1 = x2;
  27. Console.WriteLine($"x1={x1}; x2={x2}");
  28. }
  29. else
  30. {
  31. Console.WriteLine("No real roots");
  32. }
  33.  
  34.  
  35. }
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment