#include
int main()
{
int a,b;
char c;
printf("輸入運算公式(形如 1+2 )");
scanf("%d%c%d",&a,&c,&b);
switch(c)
case "+":printf("%d+%d=%d\n",a,b,a+b);
break;
case "-":printf("%d-%d=%d\n",a,b,a-b);
case "*":printf("%d*%d=%d\n",a,b,a*b);
case "/":
if ( b == 0 )
printf("被除數為0,非法!\n");
}
else
printf("%d/%d=%d\n",a,b,a/(1.0*b) );
default:
printf("輸入的運算子非法!\n");
return 0;
#include
int main()
{
int a,b;
char c;
printf("輸入運算公式(形如 1+2 )");
scanf("%d%c%d",&a,&c,&b);
switch(c)
{
case "+":printf("%d+%d=%d\n",a,b,a+b);
break;
case "-":printf("%d-%d=%d\n",a,b,a-b);
break;
case "*":printf("%d*%d=%d\n",a,b,a*b);
break;
case "/":
{
if ( b == 0 )
{
printf("被除數為0,非法!\n");
}
else
{
printf("%d/%d=%d\n",a,b,a/(1.0*b) );
}
}
break;
default:
printf("輸入的運算子非法!\n");
break;
}
return 0;
}