你定义参数和变量的方式有点不合理,全局变量和局部变量常常都定义为一个变量名了~~~~还有就是在使用的全局变量的函数中,返回的居然是全局变量?(如:return(largest);)这个让我有点汗颜。。。。你的代码我改了挺多地方(PS:其实我感觉另外重新写过比较好。。。但是我有点懒,直接在上面修改了),还有就是由于一次要输入50个数,这个调试起来比较麻烦,所以我改成只输入两个学生的数据了,你可以改 展开
你定义参数和变量的方式有点不合理,全局变量和局部变量常常都定义为一个变量名了~~~~还有就是在使用的全局变量的函数中,返回的居然是全局变量?(如:return(largest);)这个让我有点汗颜。。。。你的代码我改了挺多地方(PS:其实我感觉另外重新写过比较好。。。但是我有点懒,直接在上面修改了),还有就是由于一次要输入50个数,这个调试起来比较麻烦,所以我改成只输入两个学生的数据了,你可以改回来;还有就是帮你完善了最高分的算法,平均分方差就没搞了。。。因为我不清楚你到底需要怎么算。另外,我建议你,谨慎使用全局变量。代码如下:#include<stdio.h>#include<math.h>float score[10][5];int i,j;void main() { float aver_st(int i);float aver_score(int j);float highest(int &student,int &subject);float fc=0;float largest=0;int student=1,subject=1;printf("请输入2个学生的成绩,按照每门课顺序依次输入:\n");for(i=0;i<2;i++) { printf("第%d个学生",i+1);for(j=0;j<5;j++) {printf("第%d门课的成绩:\n",j+1);scanf("%f",&score[i][j]);} } for(i=0;i<2;++i) printf("第%d个学生的平均分为:%.2f\n",i+1,aver_st(i));for(j=0;j<5;++j) printf("第%d门课的平均分为:%.2f\n",j+1,aver_score(j));largest=highest(student,subject);printf("10个分数中最高的分数是第%d个学生的第%d门课,分数为:%.2f\n",student+1,subject+1,largest);printf("平均分方差为:%.2f\n",fc);} float aver_st(int i)/*求每个学生的平均分*/ {//float score[10][5];return ((score[i][0]+score[i][1]+score[i][2]+score[i][3]+score[i][4])/5);} float aver_score(int j)/*求每门课的平均分*/ {float y=0;//float score[10][5];for(i=0;i<2;i++) y=y+score[i][j];return (score[i][j]=y/2);} float highest(int &student,int &subject) /*找出50个分数中的最高分及对应的学生和课程*/ { float largest=0;for(i=0;i<2;++i) { for(j=0;j<5;++j) { if(largest<score[i][j]) { largest=score[i][j];student=i;subject=j;} } } return(largest);} 收起