解题思路:
注意事项:
第一次自己设置好链表,运行成功有点激动。别根据输出提示输入就行,不然运行不成功。
参考代码:
#include <stdio.h>
#include <stdlib.h>
struct student
{
char number[20];
char name[20];
int grade1;
int grade2;
int grade3;
struct student* next;
};
void CreatList(struct student* head,int N);
void input(struct student* temp);
void print(struct student* head);
int main(void)
{
struct student* head=(struct student*)malloc(sizeof(struct student));
int N; //N是学生记录数目
scanf("%d",&N);
CreatList(head,N);
print(head);
return 0;
}
/*----------------设置头结点-------------*/
void CreatList(struct student* head,int N)
{
struct student* move=head;
for(int i=1;i<=N;i++)
{
struct student* temp=(struct student*)malloc(sizeof(struct student));
move->next=temp;
input(temp);
temp->next=NULL;
move=temp;
}
}
void input(struct student* temp)
{
// printf("输入学号");
scanf("%s",temp->number);
// printf("输入名字");
scanf("%s",temp->name);
//printf("输入第一科成绩");
scanf("%d",&temp->grade1);
// printf("输入第二科成绩");
scanf("%d",&temp->grade2);
// printf("输入第三科成绩");
scanf("%d",&temp->grade3);
}
void print(struct student* head)
{
struct student* move=head->next;
while(move!=NULL)
{
printf("%s,%s,%d,%d,%d",move->number,move->name,move->grade1,move->grade2,move->grade3);
printf("\n");
move=move->next;
}
}
0.0分
1 人评分
2003年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:542 |
剪刀石头布 (C语言代码)不知道怎么直接在scanf中用枚举变量浏览:1320 |
程序员的表白 (C语言代码)浏览:668 |
WU-陶陶摘苹果2 (C++代码)浏览:977 |
简单的a+b (C语言代码)浏览:529 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:262 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:787 |
循环入门练习5 (C语言代码)浏览:840 |
C语言训练-自守数问题 (C语言代码)浏览:752 |
汽水瓶 (C语言代码)浏览:537 |