c语言有没有大佬帮帮
大佬救救孩子吧{:10_266:} #include <stdio.h>int main(void) {
double a, b, c;
char ch;
if(scanf("%lf%c%lf", &a, &ch, &b) != 3) {
printf("ERROR!\n"); return -1;
}
switch(ch) {
case '-': b = -b;
case '+': c = a + b; break;
case '/': if(b == 0) {printf("除数不能为0!\n"); return -1;}
b = 1 / b;
case '*': c = a * b; break;
default: printf("不支持的运算符'%c'\n", ch); return -1;
}
printf(">>> %lf\n", c);
return 0;
}
#include <stdio.h>
int main(void) {
double a, b, c;
char ch;
if(scanf("%lf%c%lf", &a, &ch, &b) != 3) {
printf("ERROR!\n"); return -1;
}
switch(ch) {
case '-': b = -b;
case '+': c = a + b; break;
case '/': b = b != 0 ? 1 / b : ({printf("除数不能为0!\n"); return -1; 0;});
case '*': c = a * b; break;
default: printf("不支持的运算符'%c'\n", ch); return -1;
}
printf(">>> %lf\n", c);
return 0;
}
人造人 发表于 2021-10-29 23:40
真是美妙的代码,完全活用 switch case 里面的 break(原来 switch case 语句不放 break,可以有另外一种解法)学习了,感恩。
页:
[1]