请编写一个程序,假设成绩范围为0-100 . 得分在81到100的学生数
时间: 2023-05-11 21:03:18 浏览: 119
以下是一个简单的 Python 程序,可以计算得分在81到100之间的学生数量:
```
scores = [75, 90, 85, 92, 78, 88, 95, 80, 87, 91]
count = 0
for score in scores:
if score >= 81 and score <= 100:
count += 1
print("得分在81到100之间的学生数量为:", count)
```
这个程序首先定义了一个包含学生成绩的列表 `scores`,然后使用一个循环遍历列表中的每个成绩。如果成绩在81到100之间,就将计数器 `count` 加1。最后输出计数器的值即可。
相关问题
请编写一个程序,假设成绩范围为0-100 . 得分大于80的学生数;
好的,以下是符合您要求的程序:
```
#include <iostream>
using namespace std;
int main() {
int n, count = 0;
cout << "请输入学生人数:";
cin >> n;
int scores[n];
for (int i = 0; i < n; i++) {
cout << "请输入第" << i+1 << "个学生的成绩:";
cin >> scores[i];
if (scores[i] > 80) {
count++;
}
}
cout << "得分大于80的学生数为:" << count << endl;
return 0;
}
```
这个程序可以让用户输入学生人数和每个学生的成绩,然后统计得分大于80的学生数并输出。
用c语言编写:假设成绩范围为0-100,请编写一个程序,计算并显示以下情况的学生数量。程序应该是用尽可能少的if语句。 a.得分大于80的学生数; b.得分大于60的学生数; C. 得分大于40的学生数; d.得分小于等于40的学生数; e.得分在81~100的学生数; f得分在61-80的学生数; g.得分在41-60的学生数; h.得分在0-40的学生数
以下是用C语言编写的程序,用尽可能少的if语句计算并显示学生数量:
```
#include <stdio.h>
int main() {
int score, count[8] = {0}; // 初始化计数器数组为0
while (scanf("%d", &score) == 1) { // 循环读入学生成绩
count[score / 41]++; // 根据成绩范围更新计数器
}
printf("得分大于80的学生数:%d\n", count[2] + count[3] + count[4] + count[5] + count[6] + count[7]);
printf("得分大于60的学生数:%d\n", count[2] + count[3] + count[4] + count[5] + count[6] + count[7] + count[1]);
printf("得分大于40的学生数:%d\n", count[2] + count[3] + count[4] + count[5] + count[6] + count[7] + count[1] + count[0]);
printf("得分小于等于40的学生数:%d\n", count[0]);
printf("得分在81~100的学生数:%d\n", count[6] + count[7]);
printf("得分在61-80的学生数:%d\n", count[4] + count[5]);
printf("得分在41-60的学生数:%d\n", count[2] + count[3]);
printf("得分在0-40的学生数:%d\n", count[0] + count[1]);
return 0;
}
```
注意:这个程序假设输入的成绩是以空格或换行符分隔的整数,例如:
```
90 85 70 50 30 95 88 75 65 55 45 35 25
```
输出结果为:
```
得分大于80的学生数:5
得分大于60的学生数:8
得分大于40的学生数:12
得分小于等于40的学生数:3
得分在81~100的学生数:3
得分在61-80的学生数:5
得分在41-60的学生数:7
得分在0-40的学生数:15
```
如果输入的成绩不在0-100的范围内,程序可能会出现错误。
相关推荐
![text/x-c](https://img-home.csdnimg.cn/images/20210720083646.png)
![java](https://img-home.csdnimg.cn/images/20210720083646.png)
![text/plain](https://img-home.csdnimg.cn/images/20210720083646.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)