编程:调用函数,求3个整数中的大者。在代码中加上张宇
时间: 2024-02-26 09:57:57 浏览: 13
好的,下面是求三个整数中的最大值的代码,同时加上张宇的名字:
```
#include <iostream>
using namespace std;
int max(int a, int b, int c) {
int max_num = a;
if (b > max_num) {
max_num = b;
}
if (c > max_num) {
max_num = c;
}
return max_num;
}
int main() {
int a, b, c;
cout << "请输入三个整数:" << endl;
cin >> a >> b >> c;
cout << "最大值为:" << max(a, b, c) << endl;
cout << "这段代码由张宇编写" << endl;
return 0;
}
```
相关问题
用c++语言打出调用函数,求3个整数中的大者代码
下面是一个简单的 C++ 代码示例,用于求三个整数中的最大值:
```cpp
#include <iostream>
using namespace std;
int max(int a, int b, int c) {
int max = a;
if (b > max) {
max = b;
}
if (c > max) {
max = c;
}
return max;
}
int main() {
int a, b, c;
cout << "请输入三个整数:" << endl;
cin >> a >> b >> c;
cout << "最大值是:" << max(a, b, c) << endl;
return 0;
}
```
在这个程序中,我们定义了一个 `max` 函数,它接受三个整数参数并返回它们中的最大值。在 `main` 函数中,我们从用户那里读取三个整数,并调用 `max` 函数来计算最大值,最后将结果输出到屏幕上。
用c++语言调用函数,求3个整数中的大者
可以使用下面的代码实现:
```c++
#include<iostream>
using namespace std;
int max(int a, int b, int c) {
int max = a > b ? a : b;
max = max > c ? max : c;
return max;
}
int main() {
int a, b, c;
cout << "请输入三个整数: " << endl;
cin >> a >> b >> c;
cout << "最大值是:" << max(a, b, c) << endl;
return 0;
}
```
在上面的代码中,定义了一个 `max` 函数用于求三个整数中的最大值,然后在 `main` 函数中调用了这个函数,并输出了最大值。