求每个学生3门课成绩,输出总分最高和最低的同学学生学号姓名和总分。我是怎么编的哪里错了。
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct StuNode
{
char num[10];
char name[20];
int math;
int English;
int C;
struct StuNode *next;
};
struct StuNode *create(int n)
{
struct StuNode *head=NULL,*pf,*pb,*aa,*bb;
int i,a[10],max=a[0],min=a[0];
for(i=0;i<n;i++)
{
pb=(struct StuNode *)malloc(sizeof(struct StuNode));
fflush(stdin);
printf("please input the NO:\n");
gets(pb->num);
printf("please input the name:\n");
gets(pb->name);
printf("please input the math score:\n");
scanf("%d",&pb->math);
printf("please input the English score:\n");
scanf("%d",&pb->English);
printf("please input the C score:\n");
scanf("%d",&pb->C);
a[i]=pb->math+pb->English+pb->C;
pb->next=NULL;
if(i==0) head=pb;
else pf->next=pb;
pf=pb;
if(max<a[i]) {aa=pb,max=a[i];}
if(min>a[i]) {bb=pb,min=a[i];}
}
printf("这5名学生3门课的总分分别为:\n");
for(i=0;i<n;i++)
printf("%d ",a[i]);
printf("\nNum\tName\tscore\tmax\n");
printf("%s\t%s\t%d\t",aa->num,aa->name,max);
printf("\nNum\tName\tscore\tmin\n");
printf("%s\t%s\t%d\t",bb->num,bb->name,min);
return(head);
}
void main()
{
int n;
struct StuNode *head;
printf("please input the number of student:\n");
scanf("%d",&n);
head=create(n);
}
用结构体编的啊。。