C语言编写一个程序,输入3个整数,从大到小排列他们
时间: 2023-03-29 13:00:51 浏览: 87
你好,我可以回答这个问题。以下是C语言编写一个程序,输入3个整数,从大到小排列他们的代码:
#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 ;
}
相关问题
用C语言编写,使用指针编写一个程序,使得输入四个整数,从小到大排列输出
好的,让我来回答您的问题。
以下是使用指针和C语言编写的程序,可以输入四个整数并按从小到大的顺序输出它们:
```c
#include <stdio.h>
void sort(int *a, int *b, int *c, int *d);
int main() {
int a, b, c, d;
printf("请输入四个整数:\n");
scanf("%d %d %d %d", &a, &b, &c, &d);
sort(&a, &b, &c, &d);
printf("四个整数从小到大排列的结果为:\n");
printf("%d %d %d %d", a, b, c, d);
return 0;
}
void sort(int *a, int *b, int *c, int *d) {
int temp;
if (*a > *b) {
temp = *a;
*a = *b;
*b = temp;
}
if (*a > *c) {
temp = *a;
*a = *c;
*c = temp;
}
if (*a > *d) {
temp = *a;
*a = *d;
*d = temp;
}
if (*b > *c) {
temp = *b;
*b = *c;
*c = temp;
}
if (*b > *d) {
temp = *b;
*b = *d;
*d = temp;
}
if (*c > *d) {
temp = *c;
*c = *d;
*d = temp;
}
}
```
希望这个程序可以帮到您!
C语言编写程序从键盘上输入十个整数 存入一维数组 将其按照从大到小的顺序排列
可以回答这个问题。请看下面的代码:
#include <stdio.h>
int main() {
int a[10], i, j, temp;
printf("请输入十个整数:\n");
for (i = 0; i < 10; i++) {
scanf("%d", &a[i]);
}
for (i = 0; i < 9; i++) {
for (j = i + 1; j < 10; j++) {
if (a[i] < a[j]) {
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
printf("从大到小的顺序排列为:\n");
for (i = 0; i < 10; i++) {
printf("%d ", a[i]);
}
printf("\n");
return 0;
}