C language selection and sorting
Select-based sorting is a relatively understandable sorting algorithm. Assume that you want to sort the sequences with n numbers in ascending order. The algorithm steps are as follows:
1. Find the subscript of the minimum number from the number of n stored in the array (for the algorithm, see "Calculate the most value" below), and then swap the minimum number with the number of 1st;
2. Except for 1st, we can find the subscript of the smallest number (the secondary decimal number in n) from the other n-1 numbers, and swap the number with 2nd;
3. Repeat Step 1 n-1 to complete the request.
Now let's look at the Code:
# Include
# Include
# Define n 10 int main () {int a [n], I, j, k, t; printf ("randomly generate 10 numbers less than 100: \ n "); for (I = 0; I
Running result:
Generate 10 numbers less than 100 at random and output them after sorting.