我是靠谱客的博主 拉长哈密瓜,这篇文章主要介绍C语言-数组-读入学生信息统计各分数段人数并打印,现在分享给大家,希望可以做个参考。

从键盘输入一个班(全班最多不超过30人)学生的某门课的成绩,当输入成绩为负值时,输入结束,分别实现下列功能:
 统计不及格人数并打印不及格学生名单。
 统计成绩在全班平均分及平均分之上的学生人数,并打印这些学生的名单;
统计各分数段的学生人数及所占的百分比。

编程要求

设计新函数统计各分数段的学生人数及所占的百分比。例如:
void GetDetail(float score[], int n);

测试说明

输入学生信息后,以及输出的格式为:

统计不及格人数并打印不及格学生名单,输出的内容为:


统计成绩在全班平均分及平均分之上的学生人数,并打印这些学生的名单,输出的内容为:

统计各分数段的学生人数及所占的百分比,输出的内容为:


注:分隔的空格数量为2个。

 

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <stdio.h> #define ARR_SIZE 30 int NumScore(long num[], float score[]); int getFailInfo(float score[], long num[], int n); float getAver(float score[], int n); int GetAboveAver(long num[], float score[], int n); void GetSubsection(float score[], int n); int main(void) { int n,m,aboveAver; float score[ARR_SIZE]; long num[ARR_SIZE]; printf("Please enter num and score until score<0:n"); n = NumScore(num, score); printf("Total students:%dn", n); printf("Fail:n"); m = getFailInfo(score,num,n); printf("Fail students = %dn",m); aboveAver = GetAboveAver(num,score,n); printf("Above aver students = %dn",aboveAver); GetSubsection(score, n); return 0; } int NumScore(long num[], float score[]) { int i = 0,count = 0; for(i=0; i<ARR_SIZE; i++) { scanf("%ld %f", &num[i], &score[i]); count++; if(score[i] < 0) break; } return i; } int getFailInfo(float score[], long num[], int n) { int i,count = 0; printf("number--scoren"); for(i=0; i<n; i++) { if(score[i] < 60) { count++; printf("%ld------%.0fn",num[i],score[i]); } } return count; } float getAver(float score[], int n) { int i; float sum = 0.0; for(i=0; i<n; i++) { sum += score[i]; } return sum/n; } int GetAboveAver(long num[], float score[], int n) { int count = 0; int i; float aver; aver = getAver(score,n); printf("aver = %fn",aver); printf("Above aver:n"); printf("number--scoren"); for(i=0; i<n; i++) { if(score[i] > aver) { printf("%ld------%.0fn",num[i],score[i]); count++; } } return count; } void GetSubsection(float score[], int n) { int count1,count2,count3,count4,count5,count6; count1=count2=count3=count4=count5=count6=0; int i,stu[6] = {0,0,0,0,0,0,}; for(i=0; i<n; i++) { if(score[i] < 60) count1++; else if(score[i] < 70) count2++; else if(score[i] < 80) count3++; else if(score[i] < 90) count4++; else if(score[i] < 100) count5++; else count6++; } printf(" <60 %d %.2f%%n",count1,(float)count1/n*100); printf("60--69 %d %.2f%%n",count2,(float)count2/n*100); printf("70--79 %d %.2f%%n",count3,(float)count3/n*100); printf("80--89 %d %.2f%%n",count4,(float)count4/n*100); printf("90--99 %d %.2f%%n",count5,(float)count5/n*100); printf(" 100 %d %.2f%%n",count6,(float)count6/n*100); }

 

最后

以上就是拉长哈密瓜最近收集整理的关于C语言-数组-读入学生信息统计各分数段人数并打印的全部内容,更多相关C语言-数组-读入学生信息统计各分数段人数并打印内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(60)

评论列表共有 0 条评论

立即
投稿
返回
顶部