陣列排序
給定一個長度為n的數列,將這個數列按從小到大的順序排列,1<=n<=200
#include<stdio.h>
#define N 201
int main() {
int n, i, j, temp;
scanf("%d", &n);
int a[N];
for (i = 0; i < n; i++){
scanf("%d", &a[i]);
}
for (i = 0; i < n - 1; i++) {
for (j = 0; j < n - i - 1; j++) {
if (a[j] > a[j + 1]) {
temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
}
for (i = 0; i < n; i++) {
printf("%d", a[i]);
}
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/375881.html
標籤:其他
下一篇:【資料結構】-排序-希爾排序
