1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | #include <stdio.h> #define N_DATA 8 int data[N_DATA] = { 12, 23, 98, 45, 11, 92, 56, 79 }; void print_data(int list[], int n) { int i; for (i = 0; i < n; i++) { printf("%d ", list[i]); } printf("\n"); } int find_min(int data[], int start, int n) { int i, least; least = start; for (i = start + 1; i < n; i++) { if (data[i] < data[least]) least = i; } return least; } int main(void) { int i, n, tmp; printf("Á¤·Ä Àü:"); print_data(data, N_DATA); for (i = 0; i < N_DATA; i++) { n = find_min(data, i, N_DATA); tmp = data[i]; data[i] = data[n]; data[n] = tmp; } printf("Á¤·Ä ÈÄ:"); print_data(data, N_DATA); } | cs |