码迷,mamicode.com
首页 > 其他好文 > 详细

函数模板

时间:2017-11-10 00:13:11      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:png   es2017   小数   iostream   str   template   blog   std   style   

#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;
}

技术分享

函数模板

标签:png   es2017   小数   iostream   str   template   blog   std   style   

原文地址:http://www.cnblogs.com/928990166li/p/7811608.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!