#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<math.h>
int main(void)
{
double x, y;
char ch;
printf("请输入四则运算:\n");
scanf("%lf%c%lf", &x, &ch, &y); //读入两个实数x,y和一个运算符
switch (ch) //判断ch的值
{
case'+':printf("%.2f\n", x + y); break;
case'-':printf("%.2f\n", x - y); break;
case'*':printf("%.2f\n", x * y); break;
case'/':if (fabs(y) > 1e-10) //判断分母是否为0
printf("%.2f\n", x / y);
else
printf("Wrong input\n");
break;
default:printf("Wrong input\n"); break;
}
}
”四则运算,直接输出各种情况下结果“
于 2022-06-10 21:57:46 首次发布