有n个学生,每人有m门课程的分数,要求: (1)找出总分最高的学生号; (2)找出至少有一门课分数不及格的学生号并输出其所有分数; (3)统计每门分数都在85分以上的学生人数。
时间: 2024-01-13 14:04:51 浏览: 19
好的,以下是一个 C 语言的实现例子:
```c
#include <stdio.h>
int find_max_total_score(int scores[][m], int n, int m) {
int max_total_score = 0;
int max_total_score_student = 0;
for (int i = 0; i < n; i++) {
int total_score = 0;
for (int j = 0; j < m; j++) {
total_score += scores[i][j];
}
if (total_score > max_total_score) {
max_total_score = total_score;
max_total_score_student = i;
}
}
return max_total_score_student + 1;
}
int find_failed_students(int scores[][m], int n, int m) {
int found = 0;
for (int i = 0; i < n; i++) {
int flag = 0;
for (int j = 0; j < m; j++) {
if (scores[i][j] < 60) {
flag = 1;
break;
}
}
if (flag) {
found = 1;
printf("该学生的分数为:");
for (int j = 0; j < m; j++) {
printf("%d ", scores[i][j]);
}
printf("\n");
}
}
if (!found) {
printf("没有找到分数不及格的学生\n");
}
}
int count_students(int scores[][m], int n, int m, int threshold) {
int count = 0;
for (int i = 0; i < n; i++) {
int flag = 1;
for (int j = 0; j < m; j++) {
if (scores[i][j] < threshold) {
flag = 0;
break;
}
}
if (flag) {
count++;
}
}
return count;
}
int main() {
int n, m;
printf("请输入学生人数n和课程数m:");
scanf("%d %d", &n, &m);
int scores[n][m];
printf("请输入每个学生的分数:\n");
for (int i = 0; i < n; i++) {
printf("请输入第%d个学生的%d门课程分数:", i + 1, m);
for (int j = 0; j < m; j++) {
scanf("%d", &scores[i][j]);
}
}
int max_total_score_student = find_max_total_score(scores, n, m);
printf("总分最高的学生号为:%d\n", max_total_score_student);
find_failed_students(scores, n, m);
int threshold;
printf("请输入分数阈值:");
scanf("%d", &threshold);
int count = count_students(scores, n, m, threshold);
printf("每门分数都在%d分以上的学生人数为:%d\n", threshold, count);
return 0;
}
```
在该程序中,分别定义了三个函数来实现题目中的三个要求:
- find_max_total_score 函数用于找出总分最高的学生号。函数遍历每个学生的分数信息,计算出该学生的总分,如果该学生的总分大于当前的最高总分,则更新最高总分和最高总分学生号。最后,函数返回最高总分学生号。
- find_failed_students 函数用于找出至少有一门课分数不及格的学生号并输出其所有分数。函数遍历每个学生的分数信息,判断该学生是否至少有一门课程分数不及格,如果是,则输出该学生的所有分数。
- count_students 函数用于统计每门分数都在85分以上的学生人数。函数遍历每个学生的分数信息,判断该学生是否每门课程分数都大于等于阈值,如果是,则将计数器加 1。最后,函数返回计数器的值。
在主函数中,先接收用户输入的学生人数 n、课程数 m 和每个学生的分数信息,然后分别调用以上三个函数得到结果。最后,输出结果。