大家晚上好
这道题有三个函数,average(),search1(),和search2(),通过它们分别实现求所有成绩的平均值,打出第n个学生的成绩,和找出至少有一门功课不及格的同学的学号并打印出全部成绩.
这道题前两个函数都可以实现,而第三和函数编译成功但执行失败.我看了好几天还是没找到原因
特求助于此,希大家不吝赐教,不胜感激!
main()
{void average();
void search1();
void search2();
static float score[3][4]={{65,57,70,60},{58,87,90,81},{90,99,100,98}};
average(*score,12);
search1(score,2);
search2(score,3);
}
void average(p,n)
float *p;int n;
{float *p_end;
float sum=0,aver;
p_end=p+n-1;
for(;p<=p_end;p++)
sum=sum+(*p);
aver=sum/n;
printf("average=%5.2f\n",aver);
}
void search1(p,n)
float (*p)[4];int n;
{int i;
printf("the scores of no.%d are :\n",n);
for(i=0;i<4;i++)
printf("%5.2f ",*(*(p+n)+i));
printf("\n");
}
void search2(p,n)
float (*p)[4];int n;
{int i,j,flag;
for(j=0;j<n;j++)
{flag=0;
for(i=0;i<4;i++)
if(*(*(p+j)+i)<60) flag=1;
if(flag==1)
{printf("no.%d is fail,his scores are:\n",j+1);
for(i=0;i<4;i++)
printf("%d", *(*(p+j)+i));
printf("\n");
}
}
}