#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;
}
#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);
break;
case '-':printf("%d-%d=%d\n",a-b);
break;
case '*':printf("%d*%d=%d\n",a*b);
break;
case '/':
{
if ( b == 0 )
{
printf("被除数为0,非法!\n",a/b);
}
else
{
printf("%d/%d=%d\n",a/(1.0*b) );
}
}
break;
default:
printf("输入的运算符非法!\n");
break;
}
return 0;
}