c语言输入三个数输出从小到大的顺序
时间: 2023-05-24 14:01:10 浏览: 54
可以的,下面是代码:
```c
#include <stdio.h>
int main()
{
int a, b, c;
printf("请输入三个整数:");
scanf("%d%d%d", &a, &b, &c);
if (a <= b && a <= c) {
printf("%d ", a);
if (b <= c) printf("%d %d", b, c);
else printf("%d %d", c, b);
}
else if (b <= a && b <= c) {
printf("%d ", b);
if (a <= c) printf("%d %d", a, c);
else printf("%d %d", c, a);
}
else {
printf("%d ", c);
if (a <= b) printf("%d %d", a, b);
else printf("%d %d", b, a);
}
return 0;
}
```
输入三个数,会按从小到大的顺序输出。
相关问题
用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 语句进行排序,最后输出结果即可。
c语言输入3个数从小到大输出
请任意输入三个整数a、b、c。然后按照从小到大的顺序输出这三个数。
#include <stdio.h>
int main() {
int a, b, c, temp;
printf("请分别输入a、b、c的值:\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;
}