一道c语言设计题,求助各位大佬

2024-12-21 23:13:52
推荐回答(1个)
回答1:

C语言实现简单四则运算,参考代码如下:
#include

int main()
{
float a,b,c;
char ch;
scanf("%f%c%f",&a,&ch,&b);
switch(ch){
case '+':c=a+b; break;
case '-':c=a-b; break;
case '*':c=a*b; break;
case '/':c=a/b; break;
default :
printf("Unknown operator!");
return 0;
}
printf("=%.2f",c);
return 0;
}