#include<stdio.h> //简易计算器
void menu()
{
//add—>加 sub—>减 mul—>乘 div—>除
printf("*********************************************\n");
printf("********* 1.add 2.sub ***********\n");
printf("********* 3.mul 4.div ***********\n");
printf("********* 0.exit ***********\n");
printf("*********************************************\n");
}
int add(int x, int y)
{
return x + y;
}
int sub(int x, int y)
{
return x - y;
}
int mul(int x, int y)
{
return x * y;
}
int div(int x, int y)
{
return x / y;
}
void DiaoYong(int (*p)(int,int))
{
int x = 0;
int y = 0;
printf("请输入两个整数\n");
scanf("%d %d",&x,&y);
int n=p(x,y);
printf("%d\n",n);
}
int main()
{
int input = 0;
do
{
menu();
printf("请输入选项\n");
scanf("%d",&input);
switch (input)
{
case 1:
DiaoYong(add);
break;
case 2:
DiaoYong(sub);
break;
case 3:
DiaoYong(mul);
break;
case 4:
DiaoYong(div);
break;
case 0:
printf("退出程序\n");
break;
default:
printf("数值错误,请重新输入\n");
break;
}
} while (input);
return 0;
}