void menu()
{
printf("**********************\n");
printf("**** 1.Add 2.Sub ****\n");
printf("**** 3.Mlu 4.Del ****\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 Del(int x, int y)
{
return x / y;
}
void calcu(int (*p)(int,int))
{
int x = 0;
int y = 0;
int ret = 0;
printf("请输入2个操作数:");
scanf("%d %d", &x, &y);
ret = p(x, y);
printf("%d\n", ret);
}
int main()
{
int i = 0;
do
{
menu();
printf("请输入:");
scanf("%d", &i);
switch (i)
{
case 0:
printf("退出计算器\n");
break;
case 1:
calcu(Add);
break;
case 2:
calcu(Sub);
break;
case 3:
calcu(Mul);
break;
case 4:
calcu(Del);
break;
default:
printf("输入错误,重新输入\n");
break;
}
} while (i);
return 0;
}