输出结果时,只输出列表头,然后就崩溃了。
#include<stdio.h>#define N 30
#define M 6
typedef struct
{
int number;
int name;
int grade[M];
int sgrade;
int agrade;
}student;//½¨Á¢½á¹¹Ìå
student a[30];
int main(){
int i,j,average,sum,m,n;
scanf("%d%d",&n,&m);
for(i=0;i<=n-1;i++)
{
printf("Please input the No.%2d student's number and name.\n",i+1);
scanf("%d%s",&a[i].number,&a[i].name);
for(j=0;j<=m-1;j++)
{
printf("Please input the No.%2d student's No.%d subject grades.\n",i+1,j+1);
scanf("%d",&a[i].grade[j]);
}
}
for(i=0;i<=n-1;i++)
{
sum=0;
for(j=0;j<=m-1;j++)
sum=sum+(a[i]).grade[j];
average=sum/m;
a[i].sgrade=sum;
a[i].agrade=average;
}
printf("%16s%5s%5s\n","name","sum","average");
for(i=0;i<=n-1;i++)
printf("%16s%5d%5d\n",(a[i]).name,(a[i]).sgrade,(a[i]).agrade);
}