// Machine Exercise 1 //********************************* * ******************* // count the top 10 software downloads, and the number of software downloads is 0 //****************************** * *********************** # include <stdio. h> # include <stdlib. h> # include <time. h> # define n 15 void swap (int * a, int * B) {int t; t = * A; * A = * B; * B = T ;} void main () {int num [N]; int count [N]; srand (unsigned) Time (null); // initialize the array for (INT I = 0; I <n; I ++) {num [I] = I + 1; count [I] = rand () % N; printf ("% 2D: % 3d \ n ", num [I], Count [I]);} // bubble sort for (Int J = 0; j <N-1; j ++) {for (int K = 0; k <N-1-j; k ++) {If (count [k] <count [k + 1]) {swap (& COUNT [K], & COUNT [k + 1]); swap (& num [K], & num [k + 1]) ;}} // print the result output printf ("the first five names:"); For (int K = 0; k <5; k ++) {printf ("% 3d ", num [k]);} printf ("\ n ");}
1: 8
2: 0
3: 13
4: 11
5: 7
6: 9
7: 1
8: 8
9: 4
10: 9
11: 6
12: 5
13: 6
14: 2
15: 8
top five names: 3 4 6 10 1
press any key to continue...