用C语言编写:从键盘输入某班某门课的成绩,编程打印最高分及学生序号
时间: 2023-06-13 16:03:22 浏览: 139
下面是用C语言编写的程序,实现从键盘输入某班某门课的成绩,并打印最高分及学生序号:
```c
#include <stdio.h>
#define MAX_STUDENT 100 // 最大学生数
int main()
{
int n; // 学生数
int scores[MAX_STUDENT]; // 成绩数组
int max_score = -1; // 最高分
int max_student_index; // 最高分学生的序号
printf("请输入学生数:");
scanf("%d", &n);
// 输入每个学生的成绩,并找出最高分
for (int i = 0; i < n; i++) {
printf("请输入第%d个学生的成绩:", i + 1);
scanf("%d", &scores[i]);
if (scores[i] > max_score) {
max_score = scores[i];
max_student_index = i;
}
}
// 打印最高分及学生序号
printf("最高分为%d,是第%d个学生的成绩\n", max_score, max_student_index + 1);
return 0;
}
```
运行程序,输入学生数和每个学生的成绩,程序会计算出最高分及对应的学生序号,并打印出来。
相关问题
从键盘输入某班某门课的成绩,编程打印最高分及学生序号。用c语言表示
好的,以下是使用 C 语言实现的代码:
```c
#include <stdio.h>
int main() {
int n; // 学生数
scanf("%d", &n); // 输入学生数
int max_score = -1; // 最高分
int max_score_idx = -1; // 最高分学生的序号
for (int i = 1; i <= n; ++i) {
int score; // 学生的成绩
scanf("%d", &score); // 输入学生的成绩
if (score > max_score) {
max_score = score;
max_score_idx = i;
}
}
printf("最高分为 %d,学生序号为 %d\n", max_score, max_score_idx);
return 0;
}
```
这个程序首先输入学生数 `n`,然后循环读入每个学生的成绩,并记录最高分及对应的学生序号。最后输出最高分和学生序号即可。
用c语言代码写:从键盘输入某班学生某门客的成绩(计算机班人数不超过51人),当输入成绩为负值时,表示输入结束,编程计算并打印最高分
```c
#include <stdio.h>
int main() {
int scores[51]; // 最多可以输入51个成绩
int i = 0;
int max_score = -1; // 初始化最高分为-1,保证输入的第一个非负数为最高分
while (1) {
printf("请输入第%d个学生的成绩:", i+1);
scanf("%d", &scores[i]);
if (scores[i] < 0) {
break; // 输入负数,结束输入
}
if (scores[i] > max_score) {
max_score = scores[i]; // 更新最高分
}
i++;
}
if (max_score == -1) {
printf("没有输入任何有效成绩!\n");
} else {
printf("最高分为:%d\n", max_score);
}
return 0;
}
```
相关推荐
![c](https://img-home.csdnimg.cn/images/20210720083646.png)
![](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)