解题思路:
注意事项:
第一次自己设置好链表,运行成功有点激动。别根据输出提示输入就行,不然运行不成功。
参考代码:
#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 人评分
C语言程序设计教程(第三版)课后习题10.7 (C语言代码)浏览:678 |
C语言程序设计教程(第三版)课后习题7.1 (C语言代码)浏览:761 |
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:561 |
弟弟的作业 (C++代码)浏览:1335 |
【绝对值排序】 (C语言代码)浏览:812 |
C语言训练-求1+2!+3!+...+N!的和 (C语言代码)万恶的long long浏览:902 |
用筛法求之N内的素数。 (C语言代码)浏览:880 |
1908题解浏览:677 |
母牛的故事 (C语言代码)浏览:1007 |
2^k进制数 (C语言描述,蓝桥杯)浏览:1452 |