从键盘输入5名学生的信息,包含学号,姓名,数学成绩英语成绩,C语言成绩,

求每个学生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);
}

if(min>a[i]) {bb=pb,min=a[i];}逻辑错误,刚开始”min=a[0]而开始运行后,min不可能大于a[i],要在这一句前再赋给min一个值,改为min=a[0];if(min>=a[i]) {bb=pb,min=a[i];}就行了,我已经试过了,运行成功
温馨提示:内容为网友见解,仅供参考
第1个回答  2012-05-06
pb=(struct StuNode *)malloc(sizeof(struct StuNode));
放一句在for前面 再放一句在if前面
第2个回答  2012-05-06
#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];//把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);
}
第3个回答  2012-05-06
什么意思,看不懂~~~~~追问

用结构体编的啊。。

相似回答