将输入的20名学生的成绩保存到数组中,求出其最高分,最低分,平均分。
时间: 2023-05-22 22:00:39 浏览: 195
好的,这是一个很简单的问题,以下是代码实现:
```python
scores = []
for i in range(20):
score = int(input("请输入第{}个学生的成绩:".format(i+1)))
scores.append(score)
max_score = max(scores)
min_score = min(scores)
avg_score = sum(scores) / len(scores)
print("最高分:{}".format(max_score))
print("最低分:{}".format(min_score))
print("平均分:{}".format(avg_score))
```
希望这个回答能够帮到你!
相关问题
编写程序,将输入的20名学生的成绩保存到数组中,求出其最高分,最低分,平均分
好的,这是一个简单的程序,可以实现你的需求:
```python
scores = []
for i in range(20):
score = int(input("请输入第{}名学生的成绩:".format(i+1)))
scores.append(score)
max_score = max(scores)
min_score = min(scores)
avg_score = sum(scores) / len(scores)
print("最高分:{}".format(max_score))
print("最低分:{}".format(min_score))
print("平均分:{}".format(avg_score))
```
请注意,这个程序只是一个示例,实际应用中可能需要更多的输入验证和错误处理。
用C语言将输入的20名学生的成绩保存到数组中,求出其最高分,最低分,平均分。
好的,这是一个很基础的问题,以下是代码:
```c
#include <stdio.h>
int main() {
int scores[20];
int max_score = 0, min_score = 100, sum_score = 0;
for (int i = 0; i < 20; i++) {
printf("请输入第%d个学生的成绩:", i+1);
scanf("%d", &scores[i]);
if (scores[i] > max_score) {
max_score = scores[i];
}
if (scores[i] < min_score) {
min_score = scores[i];
}
sum_score += scores[i];
}
printf("最高分:%d\n", max_score);
printf("最低分:%d\n", min_score);
printf("平均分:%f\n", (float)sum_score / 20);
return 0;
}
```
希望能帮到你!
相关推荐
![](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)