目录:
代码:
main.c
#include <stdio.h>
#include <stdlib.h>
int Max(int x, int y);
int Min(int x, int y);
int main(int argc, char**argv)
{
int x,y;
scanf("%d",&x);
scanf("%d",&y);
int select;
printf("输入1表示求最小值,2表示最大值\n");
scanf("%d",&select);
//定义函数指针
int (*p)(int, int);
if(select == 1)
{
//最小值
p = Min;
}
else if(select == 2)
{
//最大值
p =Max;
}
else
{
return -1;
}
//查找
printf("value is %d\n", p(x, y));
}
int Max(int x, int y)
{
return x > y?x:y;
}
int Min(int x, int y)
{
return x < y?x:y;
}
Makefile
main:main.c
gcc -o $@ $^
./$@
clean:
rm main