#include /* 一个学生的信息 */
struct Student{
int id; // 学号
double m_grade; // 数学成绩
double E_grade; // 英语成绩
struct Student *next;
};
struct Student* create_st(){
struct Student* st = (struct Student*)malloc(sizeof(struct Student));
printf(" 请输入学号: ");
scanf("%d", &(st->id));
printf("请输入数学成绩: ");
scanf("%lf", &(st->m_grade));
printf("请输入英语成绩: ");
scanf("%lf", &(st->E_grade));
printf("一个学生信息输入完毕\n");
st->next = NULL;
return st;
}
/* 学生信息统计列表(单向链表) */
struct St_list{
struct Student *head; // 指向表头部的指针
struct Student *tail; // 指向表尾部的指针
int count; // 当前列表中一共有多少个学生信息
};
/* 初始化学生表 */
void init(struct St_list *sl){
sl->head = NULL;
sl->count = 0;
}
/* 向表中添加一个学生 */
void add_st(struct St_list *sl){
if(sl->head == NULL){
sl->head = create_st();
sl->tail = sl->head;
}else{
sl->tail->next = create_st();
sl->tail = sl->tail->next;
}
sl->count++;
}
/* 显示学生表的所有信息 */
void show(const struct St_list *sl){
struct Student* st = sl->head;
while(st){
printf("学号:%3d,数学成绩:%3.2f,英语成绩:%3.2f\n",st->id, st->m_grade, st->E_grade);
st = st->next;
}
printf("一个有%d人",sl->count);
}
int main(){
int n;
printf("要建立一个学生表,需要多少人数: ");
scanf("%d",&n);
struct St_list sl;
init(&sl);
while(n){
add_st(&sl);
n--;
}
show(&sl);
return 0;
}
数学成绩英语成绩c语言 用链表输入一个正整数n 再输入n 个学生的学号和数学 英语 C语言成绩 要求...