/* Note:Your choice is C IDE */ /*一个具有两个数加减乘除功能的计算器*/ #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); } { printf("ID: 2013304117\n"); } }
总结:.程序稍微简单了点,初学者应多敲打代码,对编程中出现的错误细心地找出来并改正。