#include<stdio.h>
int main()
{
int fun(int x,int y,int (*p)(int,int));
int max(int,int);
int min(int,int);
int add(int,int);
int n,a,b;
printf(“please enter two number\n”);
scanf("%d %d",&a,&b);
printf(“please choose 1,2or3\n”);
scanf("%d",&n);
if(n1) fun(a,b,max);
else if(n2) fun(a,b,min);
else if(n==3) fun(a,b,add);
return 0;
}
int fun(int x,int y,int (*p)(int,int))
{
int result;
result=(*p)(x,y);
printf(“result=%d\n”,result);
}
int max(int x,int y)
{
int z;
if(x>y) z=x;
else z=y;
printf(“max=%d\n”);
return z;
}
int min(int x,int y)
{
int z;
if(x<y) z=x;
else z=y;
printf(“min=%d\n”);
return z;
}
int add(int x,int y)
{
int z;
z=x+y;
printf(“add=%d\n”);
return z;
}
选择模式,实现两个数的加减。
最新推荐文章于 2021-11-01 23:52:52 发布