1 #include<stdio.h> 2 int max(int x,int y){ 3 if(x>y){ 4 return x; 5 } 6 return y; 7 } 8 9 int min(int x,int y){ 10 if(x<y){ 11 return x; 12 } 13 return y; 14 } 15 16 int sum(int x,int y){ 17 return (x+y); 18 } 19 20 int f(int x,int y,int (*p)(int,int)){ 21 int result; 22 result=(*p)(x,y); 23 return result; 24 } 25 26 int main(){ 27 int x,y; 28 printf("请输入两个数字:\n"); 29 scanf("%d %d",&x,&y); 30 printf("两个数字较大的是:%d\n",f(x,y,max)); 31 printf("两个数字较小的是:%d\n",f(x,y,min)); 32 printf("两个数字的和是:%d\n",f(x,y,sum)); 33 printf("\n"); 34 return 0; 35 }
原文地址:https://www.cnblogs.com/Tobi/p/9237836.html
时间: 2024-10-07 20:25:21