自己做了个找不出逻辑错误- -!
帮个忙啊!
高手高高手人呢?来个撒 - -!
#include <stdio.h>
#include <malloc.h>
struct score
{
int num;
char name[15];
float score_1;
float score_2;
float score_3;
float score_av;
};
struct student
{
struct score objscore;
struct student *next;
};
struct student *head;
void paixu(struct student *p);
void main()
{
struct student *p,*q;
int i=0;
char yn='y';
struct student *pf,*pb;
printf("请输入学员信息。\n");
pb=(struct student*) malloc(sizeof(struct student));
pb->objscore.num=0;
pb->objscore.score_1=0;
pb->objscore.score_2=0;
pb->objscore.score_3=0;
pb->objscore.score_av=0;
pf=head=pb;
pf=pb;
pb->next=NULL;
do
{
pb=(struct student*) malloc(sizeof(struct student));
pb->objscore.num=0;
pb->objscore.score_1=0;
pb->objscore.score_2=0;
pb->objscore.score_3=0;
pb->objscore.score_av=0;
printf("学号:");
scanf("%d",&pb->objscore.num);
printf("姓名:");
fflush(stdin);
gets(pb->objscore.name);
printf("三门成绩:\n");
printf("成绩1: ");
scanf("%f",&pb->objscore.score_1);
printf("成绩2: ");
scanf("%f",&pb->objscore.score_2);
printf("成绩3: ");
scanf("%f",&pb->objscore.score_3);
pb->objscore.score_av=(pb->objscore.score_3+pb->objscore.score_3+pb->objscore.score_3)/3;
pf->next=pb;
pf=pb;
pb->next=NULL;
i++;
printf("是否继续(y/n)?");
fflush(stdin);
yn=getchar();
}while(yn=='y'||yn=='Y');
paixu(head->next);
p=q=head->next;
while(p!=NULL)
{
printf("学号: %d\n",p->objscore.num);
printf("姓名: %s\n",p->objscore.name);
printf("三门成绩: \n");
printf("成绩1: %.2f\n",p->objscore.score_1);
printf("成绩2: %.2f\n",p->objscore.score_2);
printf("成绩3: %.2f\n",p->objscore.score_3);
printf("平均成绩: %.2f\n",p->objscore.score_av);
p=p->next;
}
free(q);
}
void paixu(struct student *p)
{
struct student *q;
struct score temp;
q=p;
while(p!=NULL)
{
while(q!=NULL)
{
if(q->objscore.score_av > q->next->objscore.score_av)
{
temp=q->objscore;
q->objscore=q->next->objscore;
q->next->objscore=temp;
}
q=q->next;
}
p=p->next;
}
}