用c语言输入三个整数,从小到大输出
时间: 2024-05-09 13:16:52 浏览: 12
Sure, here's code for sorting three integers in C:
```
#include <stdio.h>
int main() {
int a, b, c;
printf("Enter three integers: ");
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("Sorted integers: %d %d %d", a, b, c);
return 0;
}
```
相关问题
c语言输入三个整数从小到大排序
好的,以下是一个简单的C语言代码示例,可以实现输入三个整数,然后从小到大进行排序:
```c
#include <stdio.h>
int main() {
int a, b, c, temp;
printf("请输入三个整数:");
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;
}
```
在这个代码中,我们首先定义了三个整数变量:a、b、c,以及一个临时变量temp。然后,通过`scanf`语句,从用户输入中获取这三个整数的值。
接下来,我们使用`if`语句和临时变量temp来对这三个整数进行排序。`if`语句用于比较三个数的大小关系,临时变量temp用于交换两个变量的值。最后,我们使用`printf`语句将排序后的结果输出到屏幕上。
需要注意的是,C语言中没有提供像C++中的`swap`函数,因此我们需要使用临时变量来实现变量值的交换操作。
用c语言输入三个整数按从小到大的顺序输出
可以使用以下代码实现:
```c
#include <stdio.h>
int main() {
int a, b, c;
printf("请输入三个整数:\n");
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\n", a, b, c);
return 0;
}
```
输入三个整数后,使用三个 if 语句进行排序,最后输出结果即可。