问题:
1.定义指针p—int p = 0;
2.在else之后打印数值,而没有在if里面打印
void menu()
{
printf("\n*****************************\n");
printf("********* 0.exit ***********\n");
printf("********* 1.add ***********\n");
printf("********* 2.sub ***********\n");
printf("********* 3.mul ***********\n");
printf("********* 4.div ***********\n");
printf("*****************************\n");
}int add(int a, int b)
{
return a + b;
}
int sub(int a, int b)
{
return a - b;
}
int mul(int a, int b)
{
return a * b;
}
int div(int a, int b)
{
return a / b;
}
int main()
{
int input = 0;
int a = 0;
int b = 0;
int(*p[5])(int, int) = { 0,add,sub,mul,div };
do
{
menu();
printf("请输入你的选择:");
scanf("%d", &input);
if (input >= 1 && input <= 4)
{
printf("请输入你要计算的两个数字:");
scanf("%d%d", &a, &b);
printf("%d\n", (*p[input])(a, b));
}
else if(input == 0)
{
printf("退出\n");
}
else
{
printf("error\n");
}
} while (input);
return 0;
}