#include
int main(void)
{
int data1,data2;
char op;
printf("please input data1 op data2:");
scanf("%d %c %d",&data1 ,&op ,&data2);
switch (op)
{
case '+':
printf("%d + %d = %.0fn",data1,data2,(double)data1 + (double)data2);
break;
case '-':
printf("%d - %d = %.0fn",data1,data2,(double)data1 - (double)data2);
break;
case '*':
printf("%d * %d = %.0fn",data1,data2,(double)data1 * (double)data2);
break;
case '/':
if (data2 == 0)
{
printf("Error!chu shu wei 0.");
}
else
{
printf("%d / %d = %.0fn",data1,data2,(double)data1 / (double)data2);
}
break;
case '%':
if (data2 == 0)
{
printf("Error!chu shu wei 0.");
}
else
{
printf("%d %% %d=%d3n",data1,data2,data1 % data2);
}
break;
default:
printf("Unknown operatorn");
}
return 0;
}如果要求是浮点数的话换一下数据类型就可以了