输入四个整数从小到大排列的C语言代码
时间: 2023-05-13 20:07:27 浏览: 97
数组上机题-第六章 数组new
#include <stdio.h>
int main() {
int a, b, c, d;
scanf("%d %d %d %d", &a, &b, &c, &d);
int arr[4] = {a, b, c, d};
int temp;
for (int i = 0; i < 4; i++) {
for (int j = i + 1; j < 4; j++) {
if (arr[i] > arr[j]) {
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
for (int i = 0; i < 4; i++) {
printf("%d ", arr[i]);
}
return 0;
}
阅读全文