/*main.h*/

template <class T>

T maxmum(T value1 ,T value2,T value3)
{
    T maxmumvalue=value1;
    if(value2>maxmumvalue)
    maxmumvalue=value2;
    if(value3>maxmumvalue)
    maxmumvalue=value3;
    return maxmumvalue;

}


/*main*/

#include <iostream>
#include "main.h"
using namespace std;

int main()
{
    int int1,int2,int3;
    cout <<"输入三个整数:"<<endl;
    cin >>int1>>int2>>int3;
    cout <<"最大整数是:"<<maxmum(int1,int2,int3)<<endl<<endl;

    double double1,double2,double3;
    cout <<"输入三个浮点数:"<<endl;
    cin>>double1>>double2>>double3;
    cout <<"最大浮点数是:"<<maxmum(double1,double2,double3)<<endl<<endl;

    char char1,char2,char3;
    cout <<"输入三个字符:"<<endl;
    cin >>char1>>char2>>char3;
    cout <<"最大字符是:"<<maxmum(char1,char2,char3)<<endl<<endl;
    return 0;
}

用函数模板求三整数,浮点数或字母的最大值

相关文章:

  • 2022-01-31
  • 2021-11-17
  • 2022-12-23
  • 2022-01-31
  • 2022-12-23
  • 2021-07-21
  • 2022-01-17
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-03
  • 2021-12-02
  • 2021-05-04
  • 2021-12-30
相关资源
相似解决方案