用c++比较三个数的大小代码
时间: 2023-03-30 08:01:34 浏览: 105
以下是比较三个数大小的 C 代码:
```
#include <stdio.h>
int main() {
int a, b, c;
printf("请输入三个整数:\n");
scanf("%d %d %d", &a, &b, &c);
if (a > b) {
if (a > c) {
printf("%d 最大\n", a);
} else {
printf("%d 最大\n", c);
}
} else {
if (b > c) {
printf("%d 最大\n", b);
} else {
printf("%d 最大\n", c);
}
}
return ;
}
```
相关问题
生成比较三个数的大小的C++代码
以下是比较三个数大小的 C 代码:
```
#include <stdio.h>
int main() {
int a, b, c;
printf("请输入三个整数:\n");
scanf("%d %d %d", &a, &b, &c);
if (a > b) {
if (a > c) {
printf("%d 最大\n", a);
} else {
printf("%d 最大\n", c);
}
} else {
if (b > c) {
printf("%d 最大\n", b);
} else {
printf("%d 最大\n", c);
}
}
return ;
}
```
c++比较三个数的大小
可以使用三目运算符来比较三个数的大小,具体实现如下:
```c++
#include <iostream>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
int max_num = (a > b) ? ((a > c) ? a : c) : ((b > c) ? b : c);
cout << "最大值为:" << max_num << endl;
return 0;
}
```
以上代码中,我们首先输入三个整数 a、b、c,然后使用三目运算符比较它们的大小,最后输出最大值。
相关推荐
![java](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_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)