Ответ:
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <locale>
#include <conio.h>
float a, b, c;
char d;
int p;
int main()
{
while (p != 2)
printf("1 = calculator \n 2 - exit \n");
scanf("%d", &p);
switch (p)
case 1:
float c;
printf("First number ");
scanf("%d", &a);
printf("Action with numbers ");
scanf("%s", &d);
printf("Second number ");
scanf("%d", &b);
if (d == '+')
c = a + b;
if (d == '-')
c = a - b;
if (d == '*')
c = a * b;
if (d == '/')
c = a / b;
system("cls");
}
case 2:
break;
printf("Result = %2.f \n", c);
Объяснение:
using namespace std;
char op;
double num1, num2, result;
cout << "Введите операцию (+, -, *, /): ";
cin >> op;
cout << "Введите первое число: ";
cin >> num1;
cout << "Введите второе число: ";
cin >> num2;
switch(op)
case '+':
result = num1 + num2;
case '-':
result = num1 - num2;
case '*':
result = num1 * num2;
case '/':
result = num1 / num2;
default:
cout << "Некорректная операция";
return 0;
cout << num1 << " " << op << " " << num2 << " = " << result;
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
Ответ:
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <locale>
#include <conio.h>
float a, b, c;
char d;
int p;
int main()
{
while (p != 2)
{
printf("1 = calculator \n 2 - exit \n");
scanf("%d", &p);
switch (p)
{
case 1:
{
float c;
printf("First number ");
scanf("%d", &a);
printf("Action with numbers ");
scanf("%s", &d);
printf("Second number ");
scanf("%d", &b);
if (d == '+')
c = a + b;
if (d == '-')
c = a - b;
if (d == '*')
c = a * b;
if (d == '/')
c = a / b;
system("cls");
}
case 2:
{
break;
}
}
printf("Result = %2.f \n", c);
}
}
Объяснение:
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <locale>
#include <conio.h>
float a, b, c;
char d;
int p;
int main()
{
while (p != 2)
{
printf("1 = calculator \n 2 - exit \n");
scanf("%d", &p);
switch (p)
{
case 1:
{
float c;
printf("First number ");
scanf("%d", &a);
printf("Action with numbers ");
scanf("%s", &d);
printf("Second number ");
scanf("%d", &b);
if (d == '+')
c = a + b;
if (d == '-')
c = a - b;
if (d == '*')
c = a * b;
if (d == '/')
c = a / b;
system("cls");
}
case 2:
{
break;
}
}
printf("Result = %2.f \n", c);
}
}
#include <iostream>
using namespace std;
int main()
{
char op;
double num1, num2, result;
cout << "Введите операцию (+, -, *, /): ";
cin >> op;
cout << "Введите первое число: ";
cin >> num1;
cout << "Введите второе число: ";
cin >> num2;
switch(op)
{
case '+':
result = num1 + num2;
break;
case '-':
result = num1 - num2;
break;
case '*':
result = num1 * num2;
break;
case '/':
result = num1 / num2;
break;
default:
cout << "Некорректная операция";
return 0;
}
cout << num1 << " " << op << " " << num2 << " = " << result;
return 0;
}