作者:巩俐1996 | 来源:互联网 | 2023-08-31 14:40
计算器功能就是“+”“-”“*”“/”,利用switch语句和自带的计算功能实现就行了
程序代码:
#include
int main()
{
int num1,num2;
char function;
printf("please input num1 function num2 :\n");
scanf("%d%c%d", &num1, &function, &num2);
switch(function)
{
case '+' :
printf("%d + %d = %d\n",num1,num2,num1+num2);
break;
case '-' :
printf("%d - %d = %d\n",num1,num2,num1-num2);
break;
case '*' :
printf("%d * %d = %d\n",num1,num2,num1*num2);
break;
case '/' :
printf("%d / %d = %d\n",num1,num2,num1/num2);
break;
default:
printf("error\n");
}
return 0;
}
执行程序检验: