#include"stdio.h"
main()
{
int max(int, int);
int min(int,int);
int add(int,int);
int fun(int x, int y, int(*p)(int, int));
int (*p)(int, int);
int a, b, c,n;
printf("please enter a and b:");
scanf_s("%d%d",&a,&b);
printf("please choose 1 or 2 or 3: ");
scanf_s("%d",&n);
/*
if (n == 1)p = max;
else if (n == 2) p = min;
else if (n == 3)p = add;
c = (*p)(a, b);
if(n==1)
printf("a=%d,b=%d,max=%d",a,b,c);
else if(n==2) printf("a=%d,b=%d,min=%d", a, b, c);
else if(n==3) printf("a=%d,b=%d,add=%d", a, b, c);*/
if (n == 1)fun(a, b, max);
else if (n == 2)fun(a, b, min);
else if (n == 3)fun(a, b, add);
getch();
}
int fun(int x, int y, int(*p)(int, int))
{
int result;
result = (*p)(x,y);
printf("result is :%d",result);
}
int min(int x, int y)
{
int z;
if (x < y) z = x;
else z = y;
printf("min=%d", z);
}
int max(int x, int y)
{
int z;
if (x > y) z = x;
else z = y;
return z;
printf("max=%d", z);
}
int add(int x,int y)
{
int z;
z = x + y;
return z;
printf("add=%d", z);
}
please enter a and b:500 499
please choose 1 or 2:2
a=500,b=499,max=500
please enter a and b:500 499
please choose 1 or 2:2
a=500,b=499,min=499
please enter a and b:500 499
please choose 1 or 2 or 3: 3
a=500,b=499,add=999
_by genmer