设计一个C++程序,通过重载求两个数中大数的函数max(x,y),分别实现求2个实数和2个整数的大数

2025-02-26 06:34:04
推荐回答(2个)
回答1:

#include "iostream.h"
int max(int x,int y)
{return x>y?x:y;}
float max(float x,float y)
{return x>y?x:y;}

void main()
{
int a,b;
float c,d;
cout<<"请输入两个整数和两个实数:"< cin>>a>>b;
cin>>c>>d;
cout< cout<}

回答2:

long max(long x,long y)
{
return x>y?x:y;
}
double max(double x,double y)
{
return x>y?x:y;
}
double max(long x,double y)
{
return (double)(x>y?x:y);
}