#include<stdio.h>
int main ()
{
int max(int,int);
int min(int x,int y);
int (*p)(int,int);
int a;
int b;
int c;
int n;
printf("enter a and b:");
scanf("%d,%d",&a,&b);
printf("choose 1 or 2:");
scanf("%d",&n);
if(n == 1)
{
p = max;
}
else if(n == 2)
{
p = min;
}
c = (*p)(a,b);
printf("a = %d,b = %d\n",a,b);
if(n == 1)
{
printf("max = %d\n",c);
}
else
{
printf("min = %d\n",c);
}
return 0;
}
int max(int x,int y)
{
int z;
if(x > y)
{
z = x;
}
else
{
z = y;
}
return z;
}
int min(int x,int y)
{
int z;
if(x < y)
{
z = x;
}
else
{
z = y;
}
return z;
}
输入两个整数,然后让用户选择1或者2,选1是调用max函数,输出二者中大数,选2时调用min函数输出二者中的小数(指向函数的指针变量)
最新推荐文章于 2023-01-27 10:26:19 发布