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
#include <stdio.h>
#include <stdlib.h>
#define N 10
void show_data(int *data, int n) {
for (int i = 0; i < n; i++)
printf("%5d", data[i]);
printf("\n");
}
void sort_data(int *data, int n) {
int k, min, temp;
for (int i = 0; i < n - 1; i++) {
k = i;
min = data[i];
for (int j = i + 1; j < n; j++) {
if (data[j] < min) {
min = data[j];
k = j;
}
}
temp = data[i];
data[i] = data[k];
data[k] = temp;
}
}
void main() {
int data[N];
for (int i = 0; i < N; i++)
data[i] = rand() % 100;
show_data(data, N);
sort_data(data, N);
show_data(data, N);
}