c++语言求各分数段人数
时间: 2023-09-08 19:00:38 浏览: 61
要求根据C语言成绩,求出各个分数段的人数。首先,我会定义几个分数段,例如:90分以上为优秀,80-89分为良好,70-79分为中等,60-69分为及格,60分以下为不及格。接着,我会使用一个变量来存储总人数,并初始化为0。然后,我依次询问每个学生的C语言成绩,并根据其成绩将总人数加一。在询问每个学生成绩的同时,我还会使用条件语句判断其所属的分数段,并根据判断结果将相应分数段的人数加一。最后,输出各个分数段的人数。以下是代码示例:
```c
#include <stdio.h>
int main() {
int total = 0; // 总人数
int count[5] = {0}; // 各个分数段人数,按照分数段的顺序存储
int n; // 学生人数
printf("请输入学生人数:");
scanf("%d", &n);
for (int i = 0; i < n; i++) {
int score;
printf("请输入第%d个学生的C语言成绩:", i + 1);
scanf("%d", &score);
total++; // 总人数加一
if (score >= 90) {
count[0]++; // 优秀人数加一
} else if (score >= 80) {
count[1]++; // 良好人数加一
} else if (score >= 70) {
count[2]++; // 中等人数加一
} else if (score >= 60) {
count[3]++; // 及格人数加一
} else {
count[4]++; // 不及格人数加一
}
}
printf("优秀人数:%d\n", count[0]);
printf("良好人数:%d\n", count[1]);
printf("中等人数:%d\n", count[2]);
printf("及格人数:%d\n", count[3]);
printf("不及格人数:%d\n", count[4]);
printf("总人数:%d\n", total);
return 0;
}
```
执行上述代码后,程序会要求输入学生人数和每个学生的C语言成绩,然后输出各个分数段的人数以及总人数。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)