RVBTCC/test/array/sort.c

34 lines
586 B
C
Raw Permalink Normal View History

2024-12-07 04:24:00 +00:00
int printf(char* format, ...);
int scanf(char* format, ...);
2024-12-08 07:41:38 +00:00
int exit(int status);
void swap(int* a, int* b) {
int t = *a;
*a = *b;
*b = t;
}
2024-11-17 02:39:58 +00:00
void sort(int a[], int n) {
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (a[i] > a[j]) {
2024-12-08 07:41:38 +00:00
swap(&a[i], &a[j]);
2024-11-17 02:39:58 +00:00
}
}
}
}
2024-12-08 07:41:38 +00:00
int a[100];
int n;
2024-11-17 02:39:58 +00:00
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
sort(a, n);
for (int i = 0; i < n; i++) {
printf("%d ", a[i]);
}
printf("\n");
}