# 函数重载--求中间值

#include <iostream>
using namespace std;
int  main()
{
int show(int,int,int);
long show(long,long,long);
double show(double,double,double);

int a1,b1,c1;
cin>>a1>>b1>>c1;
int maxt1=show(a1,b1,c1);
cout<<"int:"<<maxt1<<endl;

long a2,b2,c2;
cin>>a2>>b2>>c2;
long maxt2=show(a2,b2,c2);
cout<<"long:"<<maxt2<<endl;

double a3,b3,c3;
cin>>a3>>b3>>c3;
double maxt3=show(a3,b3,c3);
cout<<"double:"<<maxt3<<endl;

}

``````1 2 3
2345 1234 3456
1.11 3.22 2.22``````

``````int:2
long:2345
double:2.22``````

``````#include <stdio.h>
int main(int argc,char *argv[])
{
int a,b,c;
long d,e,f;
double g,h,i;
scanf("%d%d%d",&a,&b,&c);
scanf("%d%d%d",&f,&e,&d);
scanf("%lf%lf%lf",&g,&h,&i);
if(a>=b && b>=c || c>=b && b>=a)
printf("int:%d\n",b);
else if(b>=a && a>=c || c>=a && a>=b)
printf("int:%d\n",a);
else
printf("int:%d\n",c);
if(d>=e&&e>=f||f>=e&&e>=d)
printf("long:%d\n",e);
else if(e>=d&&d>=f||f>=d && d>=e)
printf("long:%d\n",d);
else
printf("long:%d\n",f);
if(g>=h && h>=i || i>=h && h>=g)
printf("double:%g\n",h);
else if(h>=g && g>=i || i>=g && g>=h)
printf("double:%g\n",g);
else
printf("double:%g\n",i);

return 0;
}``````

``````
#include <iostream>
using namespace std;
int  main()
{
int show(int,int,int);
long show(long,long,long);
double show(double,double,double);

int a1,b1,c1;
cin>>a1>>b1>>c1;
int maxt1=show(a1,b1,c1);
cout<<"int:"<<maxt1<<endl;

long a2,b2,c2;
cin>>a2>>b2>>c2;
long maxt2=show(a2,b2,c2);
cout<<"long:"<<maxt2<<endl;

double a3,b3,c3;
cin>>a3>>b3>>c3;
double maxt3=show(a3,b3,c3);
cout<<"double:"<<maxt3<<endl;
return 0;
}
int  show(int a, int b, int c)
{
int m;
if(c>a&&c>b)  //如果c比a和b都大
return a>b?a:b; //中间值是a和b中较大的那个值
if(c<a&&c<b)  //如果c比a和b都小
return a<b?a:b; //中间值是a和b中较小的那个值
m=a>b?a:b; //m先等于a和b中较大的那个值
m=m<c?m:c; //m等于m和c中较小的那个值，即为中间值
return m; //m为函数调用返回值
}

long  show(long a, long b,long c)
{
long m;
if(c>a&&c>b)  //如果c比a和b都大
return a>b?a:b; //中间值是a和b中较大的那个值
if(c<a&&c<b)  //如果c比a和b都小
return a<b?a:b; //中间值是a和b中较小的那个值
m=a>b?a:b; //m先等于a和b中较大的那个值
m=m<c?m:c; //m等于m和c中较小的那个值，即为中间值
return m; //m为函数调用返回值
}

double  show(double a, double b, double c)
{
double m;
if(c>a&&c>b)  //如果c比a和b都大
return a>b?a:b; //中间值是a和b中较大的那个值
if(c<a&&c<b)  //如果c比a和b都小
return a<b?a:b; //中间值是a和b中较小的那个值
m=a>b?a:b; //m先等于a和b中较大的那个值
m=m<c?m:c; //m等于m和c中较小的那个值，即为中间值
return m; //m为函数调用返回值
}``````