用链表建立三个学生的数据,按顺序输出
#include <stdio.h>
int main()
{
struct stu
{
int num;
float score;
struct stu *next;
};
struct stu student[3],*p,*head;
int i;
for(i=0;i<3;i++)
{
printf("输入第%d位同学的学号:",i+1);
scanf("%d",&student[i].num);
printf("输入第%d位同学的分数:",i+1);
scanf("%f",&student[i].score);
}
head=&student[0];
for(i=0;i<2;i++)
{
student[i].next=&student[i+1];
}
student[2].next=NULL;
p=head;
do
{
printf("同学们的学号是:%d,分数是%f\n",p->num,p->score);
p=p->next;
}while(p!=NULL);
return 0;
}
网友评论