#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
int int_computer(int num1, char *p, int num2)
{
if (p == "-a")
return num1 + num2;
else if (p == "-s")
return num1 - num2;
else if (p == "-m")
return num1 * num2;
else if (p == "-d")
return num1 / num2;
else
return -1;
}
int main(int argc,int argv)
{
char a;
char *p = &a;
int num1 = 0;
int num2 = 0;
scanf("%d%c%d", &num1, &a, &num2);
if (a == '+')
p = "-a"; //如果输入‘+’表示“-a”选项执行加法
else if (a == '-')
p = "-s"; //如果输入‘-’表示“-s”选项执行减法
else if (a == '*')
p = "-m"; //如果输入‘*’表示“-m”选项执行乘法
else if (a == '/')
p = "-d"; //如果输入‘/’表示“-d”选项执行除法
else
p = '\0';
int ret = int_computer(num1, p, num2);
printf("%d%c%d=%d\n", num1, a, num2, ret);
system("pause");
return 0;
}
转载于:https://blog.51cto.com/10740329/1713565