#include <stdio.h>
#include <stdlib.h>
int max(int a,int b)
{
return a>b?a:b;
}
int min(int a,int b)
{
return a<b?a:b;
}
int (*p)(int x,int y);
int main()
{
//int *p=NULL;
int answer;
int x,y;
printf("请输入两个整数:(输入的格式是:12 12)\n");
scanf("%d%d",&x,&y);
//int (*p)(int x,int y);
p=max;
answer=p(x,y);
printf("两者之间最大值是:%d\n",answer);
p=min;
answer=p(x,y);
printf("两者之间最小值是:%d\n",answer);
return 0;
}
下面只是有一点不同的写法
#include <stdio.h>
#include <stdlib.h>
int main()
{
int max(int x,int y);
int min(int x,int y);
int (*p)(int x,int y);
//int *p=NULL;
int answer;
int x,y;
printf("请输入两个整数:(输入的格式是:12 12)\n");
scanf("%d%d",&x,&y);
//int (*p)(int x,int y);
p=max;
answer=p(x,y);
printf("两者之间最大值是:%d\n",answer);
p=min;
answer=p(x,y);
printf("两者之间最小值是:%d\n",answer);
return 0;
}
int max(int a,int b)
{
return a>b?a:b;
}
int min(int a,int b)
{
return a<b?a:b;
}