C language Ta: Count the top 10 software downloads and the number of software downloads with 0 downloads.

Source: Internet
Author: User

 

 

 
// 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...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.