C語言不及格人數統計和打印(數組-2)


任務描述

學生成績統計

從鍵盤輸入一個班(全班最多不超過30人)學生的某門課的成績,當輸入成績為負值時,輸入結束,分別實現下列功能:

(1) 統計不及格人數並打印不及格學生名單。

(2) 統計成績在全班平均分及平均分之上的學生人數,並打印這些學生的名單;

(3) 統計各分數段的學生人數及所占的百分比。

本關任務要求在前一關的基礎上,編寫函數,實現功能(2)。

編程要求

在前一關的基礎上,增加函數GetFail,統計不及格人數並打印不及格學生名單。

測試說明

我會對你編寫的代碼進行測試:

第一關:輸入學生信息后,以及輸出的格式為:

 

 第二關:統計不及格人數並打印不及格學生名單,輸出的內容為:

 

 

 1 #include  <stdio.h>
 2 #define ARR_SIZE 30
 3 /************Begin***********/
 4 //′?′|?óé?ê?è??§éúD??¢μ?oˉêyéù?÷
 5 
 6 
 7 /************End*************/
 8 int tjStudent(int num[ARR_SIZE],float score[ARR_SIZE]){
 9     
10     int n=0;
11         for(int i=1;i<=ARR_SIZE;i++){
12     //    printf("請輸入第%d位學生的學號and成績",i);
13         scanf("%d %f",&num[i],&score[i]);
14             if(num[i]<=0 ||score[i]<=0){
15                 break;
16             }else{
17                 
18                 n++;
19             }
20         
21         }
22         return n;
23     
24 }
25 int  getFailStudent(int num[ARR_SIZE],float score[ARR_SIZE]){
26     int n=0;
27     printf("Fail:\n");
28     printf("number--score\n");
29     for(int i=1;i<11;i++){
30         if(score[i] <60){
31             
32             printf("%d------%.0f\n",num[i],score[i]);
33             n++;
34         }
35             //TODO        
36     }
37     return n;
38     
39 }
40 int main(void)
41 {
42     int n=0;
43     float score[ARR_SIZE];
44     int num[ARR_SIZE];
45     printf("Please enter num and score until score<0:\n");
46     
47     n=tjStudent(num,score);
48 
49     /************Begin***********/
50     //′?′|?óé?oˉêyμ÷ó?
51 
52     /************End*************/
53     printf("Total students:%d\n", n);
54     
55     n=getFailStudent(num,score);
56     printf("Fail students = %d\n", n);
57     return 0;
58 }
59 
60 
61 //oˉêy1|?ü£o′ó?ü?ìê?è?ò???°à?§éú?3????μ?3é?¨?°???§o?
62 //μ±ê?è?3é?¨?a?o?μê±£?ê?è??áê?£?oˉêy·μ???§éú×üêy
63 /************Begin***********/
64 
65 
66 /************End*************/

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM