[C language Ta] 35 students, each of which has four courses, are randomly generated, calculate the average score, and rank by average score

Source: Internet
Author: User
//************************************** * ******** // 10th questions/35 students, each student has four courses, which are randomly generated and the average score is calculated, rank by average score //********************************* * ************** # include <stdio. h> # include <stdlib. h> # include <time. h ># define num 10 void main () {int stuscore [num] [4]; double averagescore [num]; int sum; srand (unsigned) Time (null )); // randomly generate 35 students with four scores per person and calculate the average score for (INT I = 0; I <num; I ++) {sum = 0; for (Int J = 0; j <4; j ++) {stuscore [I] [J] = ran D () % 100 + 1; sum + = stuscore [I] [J];} averagescore [I] = sum/4.0 ;} // print the single score and average score printf ("single score (4) average score \ n"); For (int A = 0; A <num; A ++) {for (INT B = 0; B <4; B ++) {printf ("%-3D", stuscore [a] [B]);} printf ("% 8.1f", averagescore [a]); printf ("\ n");} // double temp; int maxvalue; for (Int J = 0; j <NUM-1; j ++) {maxvalue = J; For (int K = J + 1; k <num; k ++) {If (averagescore [k]> averagescore [maxvalue]) {maxvalue = K ;}} if (maxvalue! = J) {temp = averagescore [J]; averagescore [J] = averagescore [maxvalue]; averagescore [maxvalue] = temp ;}// print the score, average score, and ranking printf ("ranking: \ n"); For (int w = 0; W <num; W ++) {printf ("the average score of the % d name is: % 5.2f \ n ", W + 1, averagescore [w]);}

Average score of one unit (4)
3 52 84 1 35.0
17 41 50 90 49.5
42 40 1002 46.0
94 52 36 74 64.0
56 68 45 7 44.0
71 10 73 76 57.5
65 83 10047 73.8
13 1 28 32 18.5
61 27 80 71 59.8
85 7 96 81 67.3
Ranking:
Average score of 1st: 73.75
Average score of 2nd: 67.25
Average score of 3rd: 64.00
Average score of 4th: 59.75
Average score of 5th: 57.50
Average score of 6th: 49.50
Average score of 7th: 46.00
Average score of 8th: 44.00
Average score of 9th: 35.00
Average score of 10th: 18.50
Press any key to continue...

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.