# 函数模板---求三个数中的中间值

#include <iostream>
using namespace std;

template <typename T>
//--------------begin-----------
// 补充缺少代码
//--------------end-------------

int  main()
{
int a1,b1,c1;
cin>>a1>>b1>>c1;
int m1=middle(a1,b1,c1);
cout<<"int:"<<m1<<endl;

char a2,b2,c2;
cin>>a2>>b2>>c2;
char m2=middle(a2,b2,c2);
cout<<"char:"<<m2<<endl;

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

return 0;

}

``````1 3 2
a b c
2.2  3.3  1.1``````

``````int:2
char:b
double:2.2``````

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

template <typename T>T middle(T a,T b,T c)
{
if(((a>b)&&(b>c))||((c>b)&&(b>a)))
return (b);
if(((a>c)&&(c>b))||((b>c)&&(c>a)))
return (c);
if(((c>a)&&(a>b))||((b>a)&&(a>c)))
return (a);
}
int  main()
{
int a1,b1,c1;
cin>>a1>>b1>>c1;
int m1=middle(a1,b1,c1);
cout<<"int:"<<m1<<endl;

char a2,b2,c2;
cin>>a2>>b2>>c2;
char m2=middle(a2,b2,c2);
cout<<"char:"<<m2<<endl;

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

return 0;

}
``````