首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

问下一道编译函数的题,有runtime error,怎么改进

2013-12-17 
问下一道编译函数的题,有runtime error,如何改进#includestdio.hfloat score[10][5]float stu[10]floa

问下一道编译函数的题,有runtime error,如何改进
#include<stdio.h>
float score[10][5];
float stu[10];
float ave[5];
void student(void);
void average(void);
int highest(void);
main()
{
int i,j,n;
for(i=0;i<10;i++)
{
for(j=0;j<5;j++)
scanf("%f",&score[i][j]);
}
printf("Part 1: the averages of every student\n");
student();
for(i=0;i<10;i++)
printf("%f\n",stu[i]);

printf("Part 2: the averages of every course score\n");
average();
for(j=0;j<5;j++)
printf("%f\n",ave[j]);

printf("Part 3: a student  and  course scores of the student whose average is the highest\n");
n=highest();
printf("%d\n",n);
for(j=0;j<5;j++)
printf("%f\n",score[n][j]);

return 0;
}


void student(void)
{float s;
int i,j;
for(i=0;i<10;i++)
{
for(j=0,s=0;j<5;j++)
s+=score[i][j];
stu[i]=s/5.0;
}
}
void average(void)
{float s;
int i,j;
for(j=0;j<5;j++)
{
for(i=0,s=0;i<10;i++)
s+=score[i][j];
ave[j]=s/10.0;
}
}
int highest(void)
{
int i,k;
float high;
high=ave[0];
for(i=0;i<10;i++)
{
if(high<ave[i])
{high=ave[i];
k=i;}
}
return k;
}



[解决办法]
检查你的数组内存是否越界。

热点排行