C++编程题一道!急!!!!

2024-11-29 00:01:52
推荐回答(3个)
回答1:

#include
using namespace std;

int max(int a,int b)
{
return a>b?a:b;
}

float max(float a,float b)
{
return a>b?a:b;
}

char max(char a,char b)
{
return a>b?a:b;
}

void main()
{
cout< cout< cout<}

像这种问题用函数模板更直接

回答2:

#include
template
T max(T x,T y)
{
return x>y?x:y;
}

回答3:

#include
using namespace std;
double max(fdouble a,double b)
{
return a>b?a:b;
}
int max(int a,int b)
{
return a>b?a:b;
}

char max(char a,char b)
{
return a>b?a:b;
}

void main()
{
cout< cout< cout<}