踏上星辰


私信TA

用户名:xingchen123

访问量:2117

签 名:

等  级
排  名 6313
经  验 1372
参赛次数 0
文章发表 12
年  龄 0
在职情况 学生
学  校 湖南科技大学
专  业

  自我简介:

解题思路:

注意事项:
第一次自己设置好链表,运行成功有点激动。别根据输出提示输入就行,不然运行不成功。
参考代码:

#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 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区