C语言 学生成绩管理系统
时间: 2023-12-22 14:29:01 浏览: 88
```C
// 学生成绩管理系统示例
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// 学生信息结构体
struct student {
int num;
char name[20];
float pingshi; // 平时成绩
float shiyan; // 实验成绩
float kaoshi; // 考试成绩
struct student *next;
};
// 初始化链表
struct student *init() {
struct student *head;
head = (struct student *)malloc(sizeof(struct student));
head->next = NULL;
return head;
}
// 头插法插入学生成绩信息
struct student *insert(struct student *head) {
int judge;
while (1) {
printf("是否继续输入成绩: 1(是)/0(否) ");
scanf("%d", &judge);
if (judge == 1) {
struct student *p;
p = (struct student *)malloc(sizeof(struct student));
if (!head->next) {
head->next = p;
p->next = NULL;
} else {
p->next = head->next;
head->next = p;
}
} else {
return head;
}
}
}
// 主函数
int main() {
struct student *head;
head = init();
head = insert(head);
return 0;
}
```
阅读全文