问答题
编程题
m个人的成绩存放在score数组中,请编写函数fun(),它的功能是:将高于平均分的人数作为函数值返回,将高于平均分的分数放在up所指的数组中。
例如,当score数组中的数据为24,35,88,76,90,54,59,66,96时,函数返回的人数应该是5,up中的数据应为88,76,90,66,96。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include
#include
#include
int fun(int score[],int m, int up[])
{
}
main()
{
int i, n, up[9];
int score[9]={24,35,88,76,90,54,59,66,96};
clrscr();
n=fun(score, 9, up);
printf("/nup to the average score are: ");
for(i=0;i
【正确答案】int fun(int score[],int m, int up[])
{
int i,j=0;
float av=0.0;
for(i=0;iav) /*如果分数高于平均分,则将此分数放入up数组中*/
up[j++]=score[i];
return j; /*返回高于平均分的人数*/
}