#include<stdio.h>
#define N 5
int main(){
int arr[N];
printf("请输入%d个整数进行排序\n",N );
for (int i = 0; i < N; i++) {
scanf("%d",&arr[i]);
}
printf("\n");
for (int i = 0; i < N ; i++) {
printf("%d\t",arr[i]);
}
printf("\n");
int temp;
for (int i = 0; i < N - 1; i++) {
for (int j = 0; j < N - 2 -i; j++) {
if (arr[j] > arr[j+1]) {
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
for (int i = 0; i < N ; i++) {
printf("%d\t",arr[i]);
}
printf("\n");
return 0;
} |
|