#include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_SIZE 100 // 学生信息结构体 typedef struct { char num[10]; // 学号 char name[10]; // 姓名 char clas[10]; // 班级 char sex[10]; // 性别 float score; // 成绩 } Student; // 学生信息数组 Student studentList[MAX_SIZE]; int size = 0; 帮我添加一个可以查询学生成绩最大值和最小值的分函数代码
时间: 2024-03-25 08:39:03 浏览: 122
可以添加以下代码来实现查询学生成绩最大值和最小值的函数:
```c
// 查询学生成绩最大值和最小值
void findMinMaxScore() {
float maxScore = 0, minScore = 100;
for (int i = 0; i < size; i++) {
if (studentList[i].score > maxScore) {
maxScore = studentList[i].score;
}
if (studentList[i].score < minScore) {
minScore = studentList[i].score;
}
}
printf("成绩最高的学生信息:\n");
for (int i = 0; i < size; i++) {
if (studentList[i].score == maxScore) {
printf("学号:%s 姓名:%s 班级:%s 性别:%s 成绩:%.2f\n",
studentList[i].num, studentList[i].name,
studentList[i].clas, studentList[i].sex,
studentList[i].score);
}
}
printf("成绩最低的学生信息:\n");
for (int i = 0; i < size; i++) {
if (studentList[i].score == minScore) {
printf("学号:%s 姓名:%s 班级:%s 性别:%s 成绩:%.2f\n",
studentList[i].num, studentList[i].name,
studentList[i].clas, studentList[i].sex,
studentList[i].score);
}
}
}
```
在主函数中,可以通过调用该函数来查询学生成绩最大值和最小值:
```c
int main() {
// 添加学生信息
// ...
// 查询学生成绩最大值和最小值
findMinMaxScore();
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)
![](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)