输入三个整数xy,z.请把这三个数由大到小输出。
时间: 2024-06-13 11:07:46 浏览: 12
以下是两种C语言输入三个整数由大到小输出的例子:
1.使用if语句进行判断
```c
#include <stdio.h>
int main() {
int x, y, z, t;
printf("请输入三个数字(用空格隔开):\n");
scanf("%d %d %d", &x, &y, &z);
if (x < y) {
t = x;
x = y;
y = t;
}
if (x < z) {
t = x;
x = z;
z = t;
}
if (y < z) {
t = y;
y = z;
z = t;
}
printf("三个数从大到小排序为:%d %d %d\n", x, y, z);
return 0;
}
```
2.使用三目运算符进行判断
```c
#include <stdio.h>
int main() {
int x, y, z, t;
printf("请输入三个数字(用空格隔开):\n");
scanf("%d %d %d", &x, &y, &z);
x > y ? (x > z ? (y > z ? printf("三个数从大到小排序为:%d %d %d\n", x, y, z) : printf("三个数从大到小排序为:%d %d %d\n", x, z, y)) : printf("三个数从大到小排序为:%d %d %d\n", z, x, y)) : (y > z ? (x > z ? printf("三个数从大到小排序为:%d %d %d\n", y, x, z) : printf("三个数从大到小排序为:%d %d %d\n", y, z, x)) : printf("三个数从大到小排序为:%d %d %d\n", z, y, x));
return 0;
}
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)