C语言之用选择法对10个整数排序
int main() {
int arr[10], temp;
for (int i = 0;i < 10;i++) {
scanf("%d", &arr[i]);
}
printf("\n初始顺序:");
for (int i = 0;i < 10;i++) {
printf("%5d", arr[i]);
}
printf("\n排序顺序:");
for (int i = 0;i < 9;i++) {
for (int j = i + 1;j < 10;j++) {
if (arr[i] > arr[j]) {
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
for (int i = 0;i < 10;i++) {
printf("%5d", arr[i]);
}
return 0;
}