#include <stdio.h>
int main(int argc, const char * argv[]) {
int op;
float num1,num2,result;
result = 0.0f;
printf("请输入一个数:\n");
scanf("%f",&num1);
printf("请输入一个运算符:0.+ 1.- 2.* 3./\n");
scanf("%d",&op);
if (op < 0 || op > 3) {
printf("请输入正确的运算序号:\n");
return 0;
}
printf("请输入另一个数:\n");
scanf("%f",&num2);
switch (op) {
case 0:
result = num1 + num2;
break;
case 1:
result = num1 - num2;
break;
case 2:
result = num1 * num2;
break;
case 3:
result = num1 / num2;
break;
default:
break;
}
printf("result = %f\n",result);
return 0;
}
|
|