#includestdio h' float operandi, operand2, result; char oper printf(“请输入两个数和一个四则运算符(如:3,+,2):”) scanf("%f, %c, %f", &operandi, &oper, &operand2) case ' +' /*加法运算* result=operand1+operand2 case /*减法运算* result=operand l-operand2 /*乘法运算* brea case 'r /*除法运算* result=operand l/operand2 printf("非法的运算符!n") } printf("结果为:%fn", result)
#include"stdio.h" void main() { float operand1,operand2,result; char oper; printf(“请输入两个数和一个四则运算符(如:3,+,2):”); scanf("%f,%c,%f",&operand1,&oper,&operand2); switch(oper) { case '+': /*加法运算*/ result=operand1+operand2; break; case '-': /*减法运算*/ result=operand1-operand2; break; case '*': /*乘法运算*/ result=operand1*operand2; break; case '/': /*除法运算*/ result=operand1/operand2; break; default: printf("非法的运算符!\n"); } printf("结果为:%f\n",result); }