函数模板


#include <iostream>
using namespace std;

template<typename T>
T max(T x ,T y,T z){
    if(z>x)
    x=z;
    if(y>x)
    x=y;
    return x;
}

int main()
{
    
    int a,b,c,m;
    cout<<"请你输入三个整型的数字:"<<endl;
    cin>>a>>b>>c;
    m=max(a,b,c);
    cout<<"The max of a b and c is:"<<m<<endl;
    
    double ad,bd,cd,md;
    cout<<"请你输入三个小数类型的数字:"<<endl;
    cin>>ad>>bd>>cd;
    md=max(ad,bd,cd);
    cout<<"The max of a b and c is:"<<md<<endl;
    
    long al,bl,cl,ml;
    cout<<"请你输入三个长整型的数字:"<<endl;
    cin>>al>>bl>>cl;
    ml=max(al,bl,cl);
    cout<<"The max of a b and c is:"<<ml<<endl;
    return 0;
}

 

posted @ 2017-11-16 14:10  TOTO2  阅读(136)  评论(0编辑  收藏  举报