c 学生成绩管理系统代码
时间: 2023-07-28 16:07:39 浏览: 42
以下是一个简单的学生成绩管理系统代码,使用C语言编写:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Student {
char name[20];
int id;
int score;
};
int main() {
int n, i;
printf("请输入学生人数:");
scanf("%d", &n);
struct Student *students = (struct Student*)malloc(n * sizeof(struct Student));
for (i = 0; i < n; i++) {
printf("请输入第%d个学生的姓名、学号、成绩:", i+1);
scanf("%s%d%d", students[i].name, &students[i].id, &students[i].score);
}
printf("学生信息如下:\n");
printf("姓名\t学号\t成绩\n");
for (i = 0; i < n; i++) {
printf("%s\t%d\t%d\n", students[i].name, students[i].id, students[i].score);
}
free(students); //释放内存
return 0;
}
```
该代码使用了结构体来存储学生的姓名、学号、成绩等信息,并动态分配了内存空间来存储所有学生的信息。用户需要输入学生人数以及每个学生的具体信息,程序会输出所有学生的信息表格。最后,需要释放动态分配的内存空间,防止内存泄漏。