显示学生信息
时间: 2023-09-24 14:02:40 浏览: 65
好的,以下是实现显示学生信息的代码:
```
void display_student_info(StudentInfo *students, int student_num) {
int i;
printf("学号\t姓名\t高数\t英语\tC语言\n");
for (i = 0; i < student_num; i++) {
printf("%s\t%s\t%.1f\t%.1f\t%.1f\n", students[i].id, students[i].name, students[i].math_score, students[i].eng_score, students[i].c_score);
}
}
int main()
{
StudentInfo students[MAX_STUDENT_NUM]; //定义学生信息数组
int student_num = 0; //学生数量
int i;
//输入学生信息
printf("请输入学生信息(输入0结束):\n");
for (i = 0; i < MAX_STUDENT_NUM; i++) {
printf("请输入第%d个学生信息(学号 姓名 高等数学成绩 大学英语成绩 C语言成绩):\n", i+1);
scanf("%s", students[i].id);
if (students[i].id[0] == '0') { //输入0结束输入
break;
}
scanf("%s %f %f %f", students[i].name, &students[i].math_score, &students[i].eng_score, &students[i].c_score);
student_num++;
}
//显示学生信息
display_student_info(students, student_num);
//其他功能的实现需要用到学生信息数组和学生数量,因此需要在主函数中定义
//接下来可以实现其他功能,如计算成绩相关的统计数据、查询等等
return 0;
}
```
以上代码中,我们定义了一个 display_student_info 函数来显示学生信息,通过遍历学生信息数组来输出每一个学生的学号、姓名和三门课程的成绩。在主函数中,我们先输入学生信息,然后调用 display_student_info 函数来显示学生信息。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_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)