C语言实现用一维数组接收学生成绩,输出最高成绩学成绩和序号,(学生序号从1开始,最后一个是10)
时间: 2024-05-10 20:20:44 浏览: 13
```
#include <stdio.h>
int main()
{
int scores[10]; // 定义一维数组存储成绩
int max_score = 0; // 最高成绩变量
int max_index = 0; // 最高成绩对应的学生序号变量
int i; // 循环变量
// 输入10个学生成绩
printf("请输入10个学生的成绩:\n");
for (i = 0; i < 10; i++)
{
scanf("%d", &scores[i]);
}
// 查找最高成绩和对应的学生序号
for (i = 0; i < 10; i++)
{
if (scores[i] > max_score)
{
max_score = scores[i];
max_index = i + 1; // 学生序号从1开始
}
}
// 输出最高成绩和对应的学生序号
printf("最高成绩为:%d,对应的学生序号为:%d\n", max_score, max_index);
return 0;
}
```
相关问题
用c语言实现以下程序,已知一个班10个学生的成绩,存放在一个一维数组中,要求找出其中成绩最高的学生成绩和该生的序号
好的,以下是用C语言实现的代码:
```c
#include <stdio.h>
int main() {
int scores[10] = {80, 90, 75, 85, 95, 60, 70, 88, 92, 81}; // 存放学生成绩的数组
int max_score = scores[0]; // 假设第一个成绩是最高成绩
int max_index = 0; // 最高成绩对应的序号
// 遍历数组,找出最高成绩和对应的序号
for (int i = 1; i < 10; i++) {
if (scores[i] > max_score) {
max_score = scores[i];
max_index = i;
}
}
printf("最高成绩是:%d\n", max_score);
printf("最高成绩对应的学生序号是:%d\n", max_index);
return 0;
}
```
这里我们使用了一个循环来遍历数组,找出最高成绩和对应的序号。需要注意的是,这里假设第一个成绩是最高成绩,然后从第二个成绩开始遍历,如果找到更高的成绩就更新最高成绩和对应的序号。
c语言已知一个班10个学生的成绩,放在一个一维数组中,要求找出其中成绩最高的学生的成绩和该生的序号。
好的,这是一个很典型的数组操作问题。下面是一个 C 语言程序演示如何实现:
```c
#include <stdio.h>
#define N 10 // 学生数量
int main()
{
int scores[N] = {90, 85, 78, 92, 88, 95, 86, 79, 83, 91}; // 学生成绩
int max_score = scores[0]; // 初始化为第一个学生的成绩
int max_index = 0; // 初始化为第一个学生的序号
// 遍历数组,查找最高分和对应序号
for (int i = 1; i < N; i++) {
if (scores[i] > max_score) {
max_score = scores[i];
max_index = i;
}
}
printf("最高分为%d,对应序号为%d\n", max_score, max_index);
return 0;
}
```
输出结果为:
```
最高分为95,对应序号为5
```
这个程序首先定义了一个长度为 10 的整型数组 `scores`,里面存放了 10 个学生的成绩。然后定义了两个变量 `max_score` 和 `max_index`,用于存放最高分和对应的学生序号。
接下来通过遍历数组,逐个比较每个学生的成绩和最高分,如果发现某个学生的成绩更高,则更新最高分和对应序号。最后输出结果即可。