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;
}