编写一个程序,用来分别求2个整数、3个整数、2个双精度数和3个双精度数的最大值。要求:使用函数重载来完成。
时间: 2024-05-15 15:14:57 浏览: 15
```c++
#include <iostream>
using namespace std;
int max(int a, int b) {
return a > b ? a : b;
}
int max(int a, int b, int c) {
return max(max(a, b), c);
}
double max(double a, double b) {
return a > b ? a : b;
}
double max(double a, double b, double c) {
return max(max(a, b), c);
}
int main() {
int a = 3, b = 7, c = 5;
double x = 3.14, y = 2.718, z = 1.414;
cout << "max(" << a << ", " << b << ") = " << max(a, b) << endl;
cout << "max(" << a << ", " << b << ", " << c << ") = " << max(a, b, c) << endl;
cout << "max(" << x << ", " << y << ") = " << max(x, y) << endl;
cout << "max(" << x << ", " << y << ", " << z << ") = " << max(x, y, z) << endl;
return 0;
}
```
相关推荐
![application/x-zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![application/pdf](https://img-home.csdnimg.cn/images/20210720083512.png)