#include "stdio.h"
void main()
{
int iFirNum,iSecNum,iResult;
char ch,ch1;
printf("请输入表达式如 5+6= 然后按回车键:");
scanf("%d%c%d%c",&iFirNum,&ch,&iSecNum,&ch1);
switch(ch)
{
case '+':
iResult=iFirNum+iSecNum;
printf("%d+%d=%d\n",iFirNum,iSecNum,iResult);
break;
case '-':
iResult=iFirNum-iSecNum;
printf("%d-%d=%d\n",iFirNum,iSecNum,iResult);
break;
case '*':
iResult=iFirNum*iSecNum;
printf("%d*%d=%d\n",iFirNum,iSecNum,iResult);
break;
case '/':
iResult=iFirNum/iSecNum;
printf("%d/%d=%d\n",iFirNum,iSecNum,iResult);
break;
default:
printf("输入表达式错误或该计算器不具备 %ch 功能\n",ch);
}
} |
|