Advertisement
fuccpuff

Untitled

Feb 11th, 2025 (edited)
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.32 KB | None | 0 0
  1.             while (true)
  2.             {
  3.                 Console.WriteLine("Введите первое число:");
  4.                 double a = Convert.ToDouble(Console.ReadLine());
  5.  
  6.                 Console.WriteLine("Введите оператор (+, -, *, /, %, ^, V):");
  7.                 string op = Console.ReadLine();
  8.  
  9.                 Console.WriteLine("Введите второе число:");
  10.                 double b = Convert.ToDouble(Console.ReadLine());
  11.  
  12.                 double result = 0;
  13.  
  14.                 if (op == "+")
  15.                 {
  16.                     result = a + b;
  17.                 }
  18.  
  19.                 else if (op == "-")
  20.                 {
  21.                     result = a - b;
  22.                 }
  23.  
  24.                 else if (op == "*")
  25.                 {
  26.                     result = a * b;
  27.                 }
  28.  
  29.                 else if (op == "/")
  30.                 {
  31.                     if (b == 0)
  32.                     {
  33.                         Console.WriteLine("Делить на ноль нельзя!");
  34.                         continue;
  35.                     }
  36.                     result = a / b;
  37.                 }
  38.  
  39.                 else if (op == "%")
  40.                 {
  41.                     if (b == 0)
  42.                     {
  43.                         Console.WriteLine("Делить на ноль нельзя!");
  44.                         continue;
  45.                     }
  46.                     result = a % b;
  47.                 }
  48.                 // возведение в степень
  49.                 else if (op == "^")
  50.                 {
  51.                     result = Math.Pow(a, b);
  52.                 }
  53.                 // корень
  54.                 else if (op == "V")
  55.                 {
  56.                     if (b == 0)
  57.                     {
  58.                         Console.WriteLine("Корень нулевой степени не существует");
  59.                         continue;
  60.                     }
  61.                     result = Math.Pow(a, 1.0 / b);
  62.                 }
  63.                 // несуществующая операция
  64.                 else
  65.                 {
  66.                     Console.WriteLine("Неверный оператор");
  67.                     continue;
  68.                 }
  69.  
  70.                 Console.WriteLine($"Результат: {result}");
  71.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement