fork download
  1. using System;
  2.  
  3. namespace ExpressionChecker
  4. {
  5. class Program
  6. {
  7. static void Main()
  8. {
  9. Console.WriteLine("Введите X:");
  10. double x;
  11. if (!double.TryParse(Console.ReadLine(), out x))
  12. {
  13. Console.WriteLine("Некорректный ввод числа.");
  14. return;
  15. }
  16.  
  17. Console.WriteLine("Выберите выражение (1, 2 или 3):");
  18. int n;
  19. if (!int.TryParse(Console.ReadLine(), out n) || n < 1 || n > 3)
  20. {
  21. Console.WriteLine("Некорректный номер выражения.");
  22. return;
  23. }
  24.  
  25. bool correct = false;
  26. switch (n)
  27. {
  28. case 1:
  29. correct = Math.Abs(6 * x - 10.2 - (4 * x - 2.2)) < 1e-6;
  30. break;
  31. case 2:
  32. correct = Math.Abs(15 - (3 * x - 3) - (5 - 4 * x)) < 1e-6;
  33. break;
  34. case 3:
  35. correct = Math.Abs(2 * (x - 0.5) + 1 - 9) < 1e-6;
  36. break;
  37. }
  38.  
  39. Console.WriteLine(correct ? "Верно" : "Неверно");
  40. }
  41. }
  42. }
Success #stdin #stdout 0.05s 30176KB
stdin
4
1
stdout
Введите X:
Выберите выражение (1, 2 или 3):
Верно