Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- while (true)
- {
- Console.WriteLine("Введите первое число:");
- double a = Convert.ToDouble(Console.ReadLine());
- Console.WriteLine("Введите оператор (+, -, *, /, %, ^, V):");
- string op = Console.ReadLine();
- Console.WriteLine("Введите второе число:");
- double b = Convert.ToDouble(Console.ReadLine());
- double result = 0;
- if (op == "+")
- {
- result = a + b;
- }
- else if (op == "-")
- {
- result = a - b;
- }
- else if (op == "*")
- {
- result = a * b;
- }
- else if (op == "/")
- {
- if (b == 0)
- {
- Console.WriteLine("Делить на ноль нельзя!");
- continue;
- }
- result = a / b;
- }
- else if (op == "%")
- {
- if (b == 0)
- {
- Console.WriteLine("Делить на ноль нельзя!");
- continue;
- }
- result = a % b;
- }
- // возведение в степень
- else if (op == "^")
- {
- result = Math.Pow(a, b);
- }
- // корень
- else if (op == "V")
- {
- if (b == 0)
- {
- Console.WriteLine("Корень нулевой степени не существует");
- continue;
- }
- result = Math.Pow(a, 1.0 / b);
- }
- // несуществующая операция
- else
- {
- Console.WriteLine("Неверный оператор");
- continue;
- }
- Console.WriteLine($"Результат: {result}");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement