填空题 C语言
题号 #2253905

给定程序的功能是计算score中m个人的平均成绩aver,将低于aver的成绩放在below中,通过函数名返回人数。
例如,当score=(10,20,30,40,50,60,70,80,90},m= 9时,函数返回的人数应该是4,below={10,20,30,40}。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
#include%string.h>
int fun(int score[],int m,int below[])
{
int i,j=0;
float aver=0.0;
for(i=0;i<m;i++)
aver+=score[i]:
aver/=(float)m:
for(i=0;i<m; i++)
if(score[i]<aver)
below[j++]= 【1】 ;
return j;
}
void main()
{
int i,n,below[9];
int score[9]={10,20,30,40,50,60,70,80,90);
n=fun(score,9, 【2】);
printf("\n Below the average score are:%d\n",n);
for(i=0;i<n;i++)
printf("%d", 【3】 );
}

进入在线模考

参考答案

暂无

答案解析

【1】score[i]或*(score+i)【2】below【3】below[i]或*(below+i)
【解析】fun()函数的功能是返回低于平均成绩的人数,通过for循环遍历数组score,求和存入变量aver,然后计算出平均值。第二个循环将低于平均成绩的数据赋值数组b,因此第【1】处填“score[1]”或“*(score+i)”;在主函数中调用函数fun()时,最后一个参数应填入数组名blew,即将低分考生数据存入数组blew中,然后语句“printf("\n Be—low the average score are:%d"n);”输出低分考生个数,n 值即fun()函数返回值也就是低分考生的人数值。最后,利用循环输出below中的结果。

你可能感兴趣的试题

找试题 · 找答案 · 找资料 在线模考