C语言 读入学生信息并统计(一维数组和函数综合练习)
任务描述
从键盘输入一个班(全班最多不超过30人)学生的某门课的成绩,当输入成绩为负值时,输入结束,分别实现下列功能:
(1) 统计不及格人数并打印不及格学生名单。
(2) 统计成绩在全班平均分及平均分之上的学生人数,并打印这些学生的名单;
(3) 统计各分数段的学生人数及所占的百分比。
本关任务为:输入学生信息并统计,当输入成绩为负值时,输入结束;输入结束后需要统计输入的学生人数并输出。
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 26 int main(void) 27 { 28 int n=0; 29 float score[ARR_SIZE]; 30 int num[ARR_SIZE]; 31 printf("Please enter num and score until score<0:\n"); 32 33 n=tjStudent(num,score); 34 /************Begin***********/ 35 //′?′|?óé?oˉêyμ÷ó? 36 37 38 39 /************End*************/ 40 printf("Total students:%d\n", n); 41 return 0; 42 } 43 44 45 //oˉêy1|?ü£o′ó?ü?ìê?è?ò???°à?§éú?3????μ?3é?¨?°???§o? 46 //μ±ê?è?3é?¨?a?o?μê±£?ê?è??áê?£?oˉêy·μ???§éú×üêy 47 /************Begin***********/ 48 49 50 /************End*************/