运行时非正常结束,指点下喽
#include<stdio.h>struct student
{
char name[10];
int grade[3],average;
long int xuehao;
}stu[5];
int main()
{
int i,j,s,sum=0,max,m,t=0,c,e,a,b,h,f,av;
int d[5];
int math[5],chinese[5],english[5],average[5];
struct student stu[5];
for(i=0;i<5;i++)
{
printf("enter xuehao:");
scanf("%d",&stu[i].xuehao);
printf("enter name:");
scanf("%s",stu[i].name);
printf("enter the grades[3]:\n");
for(j=0,s=0;j<3;j++)
{
scanf("%d",&stu[i].grade[j]);
s=s+stu[i].grade[j];
}
average[i]=s/3;
stu[i].average=average[i];
}
for(i=0;i<5;i++)
{
math[i]=stu[i].grade[0];
chinese[i]=stu[i].grade[1];
english[i]=stu[i].grade[2];
}
m=0;
c=0;
e=0;
for(i=0;i<5;i++)
{
if(m<math[i])
{
m=math[i];a=i;
}
if(c<chinese[i])
{
b=i;c=chinese[i];
}
if(e<english[i])
{
h=i;e=english[i];
}
}
printf("math最高的学生:%ld %s %d\n",stu[a].xuehao,stu[a].name,stu[a].grade[0]);
printf("chinese最高的学生:%ld %s %d\n",stu[b].xuehao,stu[b].name,stu[b].grade[1]);
printf("english最高的学生:%ld %s %d\n",stu[h].xuehao,stu[h].name,stu[h].grade[2]);
av=average[1]; max=0;
for(i=0;i<5;i++)
{
if(av<average[i])
{f=i;av=average[i];}
}
printf("平均分最高的学生:%ld %s %d\n",stu[f].xuehao,stu[f].name,av);
for(j=0,i=0;j<5,i<5;j++,i++)
{
if(av<average[j])
{ d[i]=j;av=average[j];}
}
printf("number\tname\tmath\tchinese\tenglish\taverage\n");/*只运行到这个地方就不再运行且提示关闭程序*/
for(i=0;i<5;i++)
printf("%ld\t%s\t%d\t%d\t%d\t%d\n",stu[d[i]].xuehao,stu[d[i]].name,stu[d[i]].grade[0],stu[d[i]].grade[1],stu[d[i]].grade[2],stu[d[i]].average);
return 0;
}