函数模板

#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;
    cin>>a>>b>>c;
    m=max(a,b,c);
    cout<<"the max is "<<m<<endl;

    short ac,bc,cc,m2;
    cin>>ac>>bc>>cc;
    m2=max(ac,bc,cc);
    cout<<"the max is "<<m2<<endl;
    
    double ad,bd,cd,m3;
    cin>>ad>>bd>>cd;
    m3=max(ad,bd,cd);
    cout<<"the max is "<<m3<<endl;
    return 0;
}

 

 

 

posted on 2017-11-09 20:49  三叶癌  阅读(120)  评论(0编辑  收藏  举报

导航