用C语言编写一个输入三个数,从小到大排序
时间: 2023-03-22 16:03:48 浏览: 288
好的,以下是使用C语言编写一个输入三个数,并进行从小到大排序的程序:
```
#include <stdio.h>
int main() {
int a, b, c;
printf("请输入三个整数:");
scanf("%d %d %d", &a, &b, &c);
if (a > b) {
int temp = a;
a = b;
b = temp;
}
if (a > c) {
int temp = a;
a = c;
c = temp;
}
if (b > c) {
int temp = b;
b = c;
c = temp;
}
printf("从小到大排序后的结果为:%d %d %d", a, b, c);
return 0;
}
```
这个程序中,首先通过`scanf()`函数从控制台读入三个整数。然后使用三个`if`语句进行从小到大排序,最后使用`printf()`函数输出排序后的结果。
相关问题
用C语言编写:输入三个数请把这三个数从小到大输出
好的,以下是用C语言编写,输入三个数请把这三个数从小到大输出的代码:
```c
#include <stdio.h>
int main() {
int a, b, c, t;
printf("请输入三个数:\n");
scanf("%d%d%d", &a, &b, &c);
if (a > b) {
t = a;
a = b;
b = t;
}
if (a > c) {
t = a;
a = c;
c = t;
}
if (b > c) {
t = b;
b = c;
c = t;
}
printf("从小到大排序后的结果为:%d %d %d\n", a, b, c);
return 0;
}
```
运行结果如下:
```
请输入三个数:
9
2
5
从小到大排序后的结果为:2 5 9
```
c语言三个数排序从小到大
以下是使用 C 语言编写的三个数排序从小到大的代码:
```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;
}
```
运行程序后,会提示用户输入三个整数,然后将它们从小到大排序,并输出结果。