70,037
社区成员
发帖
与我相关
我的任务
分享#include"stdio.h"
#include"malloc.h"
#include"stdlib.h"
struct Student
{
char ID[20];
char name[50];
float score;
struct Student *next;
};
main()
{
struct Student *linkhead,*linktail,*student;
float avescore;
int totalstudent;
linkhead=linktail=NULL;
while(1)
{
student=malloc(sizeof(struct Student));
scanf("%s %s %f",student->ID,student->name,&student->score);
if(student->score<0)
{
free(student);
break;
}
student->next=NULL;
if(linktail==NULL)
{
linkhead=linktail=student;
}
else
{
linktail->next=student;
linktail=student;
}
}
avescore=0.0;
totalstudent=0;
while(student!=NULL)
{
totalstudent++;
avescore=avescore+student->score;
student=student->next;
}
avescore=avescore/totalstudent;
printf("平均分:%5.2f\n",avescore);
while(linkhead!=NULL)
{
student=linkhead;
linkhead=student->next;
free(student);
}
return 0;
}#include"stdio.h"
#include"malloc.h"
#include"stdlib.h"
struct Student
{
char ID[20];
char name[50];
float score;
struct Student *next;
};
main()
{
struct Student *linkhead,*linktail,*student;
float avescore;
int totalstudent;
linkhead=linktail=NULL;
while(1)
{
student=malloc(sizeof(struct Student));
scanf("%s %s %f",student->ID,student->name,&student->score);
student->next=NULL;//////////////////
if(student->score<0)
{
free(student);
break;
}
if(linktail==NULL)
{
linkhead=linktail=student;
}
else
{
linktail->next=student;
linktail=student;
}
}
avescore=0.0;
totalstudent=0;
student = linkhead;//////////
while(student!=NULL)
{
totalstudent++;
avescore=avescore+student->score;
student=student->next;
}
avescore=avescore/totalstudent;
printf("平均分:%5.2f\n",avescore);
while(linkhead!=NULL)
{
student=linkhead;
linkhead=student->next;
free(student);
}
return 0;
}