源码
#include <iostream.h>
int max (int x, int y);
int min (int x, int y);
int add (int x, int y);
int process (int x, int y, int (*fun)(int x, int y));
int main ()
{
int a, b;
cout<<"enter a and b :"<<endl;
cin>>a;
cin>>b;
cout<<"max=";
process(a,b,max);
cout<<"min=";
process(a,b,min);
cout<<"add=";
process(a,b,add);
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;
}
int add (int x, int y)
{
int z;
z=x+y;
return z;
}
int process (int x, int y, int (*fun)(int x, int y))
{
int result;
result=(*fun)(x,y);
cout<<result<<endl;
return result;
}
效果