写一个从大到下排序a,b,c的C语言
时间: 2024-06-03 22:08:49 浏览: 7
程序:
#include <stdio.h>
int main() {
int a, b, c, temp;
printf("请输入三个整数:\n");
scanf("%d%d%d", &a, &b, &c);
if (a < b) {
temp = a;
a = b;
b = temp;
}
if (a < c) {
temp = a;
a = c;
c = temp;
}
if (b < c) {
temp = b;
b = c;
c = temp;
}
printf("从大到小排序后的结果为:%d %d %d\n", a, b, c);
return 0;
}
相关问题
c语言a,b,c排序由小到大
我可以回答这个问题。c语言中,可以使用if语句和循环语句来实现a,b,c排序由小到大的功能。具体实现方法可以参考以下代码:
```
#include <stdio.h>
int main()
{
int a, b, c, temp;
printf("请输入三个整数:\n");
scanf("%d%d%d", &a, &b, &c);
if (a > b)
{
temp = a;
a = b;
b = temp;
}
if (a > c)
{
temp = a;
a = c;
c = temp;
}
if (b > c)
{
temp = b;
b = c;
c = temp;
}
printf("排序后的结果为:%d %d %d\n", a, b, c);
return 0;
}
```
以上代码可以实现输入三个整数,然后将它们从小到大排序后输出。
三个整数从大到小排序c语言
一个实现三个整数从大到小排序的C语言方法是使用三个变量来存储这三个整数,并使用条件语句比较它们的大小,然后将它们按顺序赋值给另外三个变量。最后,输出这三个变量的值即可。
```c
int main() {
int a, b, c, first, second, third;
printf("请输入三个整数:");
scanf("%d%d%d", &a, &b, &c);
if (a >= b && a >= c) {
first = a;
if (b >= c) {
second = b;
third = c;
} else {
second = c;
third = b;
}
} else if (b >= a && b >= c) {
first = b;
if (a >= c) {
second = a;
third = c;
} else {
second = c;
third = a;
}
} else {
first = c;
if (a >= b) {
second = a;
third = b;
} else {
second = b;
third = a;
}
}
printf("从大到小排序的结果为: %d, %d, %d\n", first, second, third);
}
```
相关推荐
![text/plain](https://img-home.csdnimg.cn/images/20210720083646.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)