|
5啊哈币
#include <stdio.h>
#include <stdlib.h>
float a[3];
struct stduent
{
int num;
struct stduent *next;
};
struct stduent *creat (int n)
{
struct stduent *head,*last,*p;
int i;
float s1,s2,s3;
head=last=NULL;
for (i=0;i<n;i++)
{
p=(struct stduent *)malloc(sizeof(struct stduent));
printf("\nPlease input student%d number:",i++);
scanf ("%d",&p->num);
printf ("score1:");
scanf ("%f",&s1);
printf ("score2:");
scanf ("%f",&s2);
printf ("score3:");
scanf ("%f",&s3);
a[i]=(((s1)+(s2)+(s3))/3);
p->next=NULL;
if (i=0)
head=last=p;
else
{
last->next=p;
last=p;
}
}
return head;
}
main(){
int i=0;
struct stduent *head,*p;
head=creat(5);
while (head!=NULL)
{
printf ("%5d,%5.1f\n",p->num,a[i]);
p=p->next;
i++;
}
}
|
最佳答案
查看完整内容
31行 if (i=0)
i=0的值还是0, 这个选择支从来进不去,所以还是对NULL进行操作
49行 a
这通不过编译的
24,26,28三行,float对应的占位符是%f,不是%d
|