|
3鱼币
直接上代码:
/********************************************************************
* 本程序是建立一个含有学生(学号、成绩)数据的单向动态链表 *
********************************************************************/
#include <stdio.h>
struct student
{
long int num;
float razults;
struct student *next;
};
void main()
{
struct student stu[100],*head;
int i=1,j,k;
while(1)
{
printf("请输入学号: \n");
scanf("%ld",&stu[i].num );
if(stu[i].num==0)
{
j=i;
stu[i-1].next =NULL;
break;
}
else
{
if(i==1)
{
head=&stu[i];
}
else
{
stu[i-1].next =&stu[i];
}
}
printf("请输入成绩: \n");
scanf("%.2f",&stu[i].razults );
i++;
}
do
{
printf("学号: %ld\t成绩: %.2f\n",head->num ,head->razults );
head=head->next ;
}while(head);
}
想了很久,此程序可运行,但给出的结果却不正确,如图:
我现在就是想不明白为什么第一次scanf可以输入,循环后学号和成绩就一起刷出来让我输入了。连88也变成学号了,成绩一个也没有。这到底是什么问题? |
最佳答案
查看完整内容
。。。首先。。既然是链表为什么还要用数组?很混乱。
至于输入问题。把 .2f的.2去掉。。输入是不能规定精度的。。
|