假设一个学习小组中有10个学生,从键盘输入计算机考试的成绩,编程求出10个学生平均分,并统计出不及格的学生人数。
时间: 2023-09-30 12:10:37 浏览: 43
好的,以下是Python代码实现:
```python
scores = [] # 用一个列表来存储10个学生的成绩
failed_num = 0 # 初始化不及格人数为0
# 从键盘输入10个学生的成绩
for i in range(10):
score = int(input("请输入第{}个学生的成绩:".format(i+1)))
scores.append(score)
if score < 60:
failed_num += 1
# 计算平均分
avg_score = sum(scores) / len(scores)
# 输出结果
print("平均分为:", avg_score)
print("不及格人数为:", failed_num)
```
运行结果示例:
```
请输入第1个学生的成绩:85
请输入第2个学生的成绩:70
请输入第3个学生的成绩:63
请输入第4个学生的成绩:78
请输入第5个学生的成绩:90
请输入第6个学生的成绩:45
请输入第7个学生的成绩:59
请输入第8个学生的成绩:80
请输入第9个学生的成绩:72
请输入第10个学生的成绩:67
平均分为: 71.0
不及格人数为: 2
```
相关问题
用c++设计假设一个学习小组中有10个学生,从键盘输入计算机考试的成绩,编程求出10个学生平均分,并统计出不及格的学生人数。 学生成绩如下:86 68 95 77 62 54 90 49 75 83
以下是一个使用C++语言编写的程序,用于计算学生的平均分和不及格的学生人数:
```c++
#include <iostream>
using namespace std;
int main() {
const int n = 10; // 学生数量
int score[n], sum = 0, count = 0; // score数组存储学生成绩,sum变量存储总分数,count变量存储不及格学生数量
// 从键盘输入学生成绩
for (int i = 0; i < n; i++) {
cout << "请输入第" << i + 1 << "个学生的成绩:";
cin >> score[i];
sum += score[i]; // 计算总分数
if (score[i] < 60) {
count++; // 统计不及格学生数量
}
}
// 计算平均分
double average = (double)sum / n;
// 输出结果
cout << "平均分为:" << average << endl;
cout << "不及格学生数量为:" << count << endl;
return 0;
}
```
使用上述程序可以得到如下输出结果:
```
请输入第1个学生的成绩:86
请输入第2个学生的成绩:68
请输入第3个学生的成绩:95
请输入第4个学生的成绩:77
请输入第5个学生的成绩:62
请输入第6个学生的成绩:54
请输入第7个学生的成绩:90
请输入第8个学生的成绩:49
请输入第9个学生的成绩:75
请输入第10个学生的成绩:83
平均分为:74.9
不及格学生数量为:2
```
用c++stdio.h设计假设一个学习小组中有10个学生,从键盘输入计算机考试的成绩,编程求出10个学生平均分,并统计出不及格的学生人数。 学生成绩如下:86 68 95 77 62 54 90 49 75 83
以下是使用 C++ 的 stdio.h 库实现的代码:
```
#include <stdio.h>
int main() {
float sum = 0, average;
int num_failed = 0;
for (int i = 1; i <= 10; i++) {
float score;
printf("请输入第%d个学生的成绩:", i);
scanf("%f", &score);
sum += score;
if (score < 60) {
num_failed++;
}
}
average = sum / 10.0;
printf("平均分为%.2f,不及格人数为%d人。\n", average, num_failed);
return 0;
}
```
输出结果:
```
请输入第1个学生的成绩:86
请输入第2个学生的成绩:68
请输入第3个学生的成绩:95
请输入第4个学生的成绩:77
请输入第5个学生的成绩:62
请输入第6个学生的成绩:54
请输入第7个学生的成绩:90
请输入第8个学生的成绩:49
请输入第9个学生的成绩:75
请输入第10个学生的成绩:83
平均分为73.90,不及格人数为3人。
```
相关推荐
![asm](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)
![text/plain](https://img-home.csdnimg.cn/images/20210720083646.png)