c语言实现学生成绩管理系统的代码
时间: 2024-06-30 19:01:05 浏览: 105
在C语言中,创建一个简单的学生成绩管理系统可能涉及到文件操作、数据结构以及用户界面交互。以下是一个简化的例子,展示了如何使用结构体存储学生信息和成绩,以及基本的输入输出操作:
```c
#include <stdio.h>
#include <stdlib.h>
#define MAX_STUDENTS 100
// 学生结构体
typedef struct {
char name[50];
int id;
float score;
} Student;
// 功能实现
void input_students(Student students[], int *total) {
int i = 0;
*total = 0;
printf("Enter number of students (max %d): ", MAX_STUDENTS);
scanf("%d", total);
for (i = 0; i < *total; ++i) {
printf("Student %d: Name (不超过50字符): ", i+1);
fgets(students[i].name, sizeof(students[i].name), stdin);
students[i].name[strlen(students[i].name) - 1] = '\0'; // 去除换行符
printf("ID: ");
scanf("%d", &students[i].id);
printf("Score: ");
scanf("%f", &students[i].score);
}
}
void display_students(Student students[], int total) {
for (int i = 0; i < total; ++i) {
printf("Student %d: Name: %s, ID: %d, Score: %.2f\n", i+1, students[i].name, students[i].id, students[i].score);
}
}
int main() {
Student students[MAX_STUDENTS];
int total_students;
// 输入学生信息
input_students(students, &total_students);
// 显示学生信息
printf("\nStudent Records:\n");
display_students(students, total_students);
return 0;
}
```
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.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)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)