C语言输入10个学生的成绩保存到数组中,输出最低分的学生成绩和序号
时间: 2023-05-17 13:04:17 浏览: 98
以下是C语言代码:
```c
#include <stdio.h>
int main() {
int scores[10];
int min_score = 100;
int min_index = 0;
for (int i = 0; i < 10; i++) {
printf("请输入第%d个学生的成绩:", i+1);
scanf("%d", &scores[i]);
if (scores[i] < min_score) {
min_score = scores[i];
min_index = i;
}
}
printf("最低分的学生成绩为%d,序号为%d\n", min_score, min_index+1);
return 0;
}
```
注意:这个问题是编程类的问题,可以回答。
相关问题
从键盘输入10个学生的c语言成绩到数组中,求平均分、最高分和最低分
题意:从键盘输入10个学生的C语言成绩,求平均分、最高分和最低分。
首先需要将输入的成绩存入一个数组中,然后可以通过遍历数组求出总成绩,从而计算平均分。最高分和最低分可以通过遍历数组比较每个成绩来得到。具体代码可以:
```python
scores = [] # 创建一个数组,用于存储成绩
# 通过for循环依次输入10位学生的成绩
for i in range(10):
score = float(input('请输入第{}个学生的成绩:'.format(i+1)))
scores.append(score) # 将输入的成绩添加到数组中
total_score = sum(scores) # 计算总成绩
average_score = total_score / len(scores) # 计算平均分
max_score = max(scores) # 获取最高分
min_score = min(scores) # 获取最低分
print('平均分为:{:.2f}'.format(average_score))
print('最高分为:{}'.format(max_score))
print('最低分为:{}'.format(min_score))
```
C语言中输入10个学生的成绩,输出最低分与最高分
```c
#include <stdio.h>
int main() {
int i;
float scores[10];
float max_score = 0.0, min_score = 100.0;
printf("请输入10个学生的成绩:\n");
for(i = 0; i < 10; i++) {
scanf("%f", &scores[i]);
if(scores[i] > max_score) {
max_score = scores[i];
}
if(scores[i] < min_score) {
min_score = scores[i];
}
}
printf("最高分为:%.2f\n", max_score);
printf("最低分为:%.2f\n", min_score);
return 0;
}
```
说明:
1. 定义一个长度为10的数组存储10个学生的成绩。
2. 初始将最高分设为0,最低分设为100,这样可以确保任何成绩都比最高分低,比最低分高。
3. 使用for循环输入10个学生的成绩,并比较每个成绩与当前最高分和最低分,更新最高分和最低分。
4. 最后输出最高分和最低分。