网友您好, 请在下方输入框内输入要搜索的题目:
下列给定程序中,函数fun()的功能是:从n个学生的成绩中统计出高于平均分的学生人数,人数由函数值返回,平均分存放在形参aver所指的存储单元中。例如输入8名学生的成绩:
85 65.5 69 95.5 87 55 62.5 75
则高于平均分的学生人数为4(平均分为74.312500)。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <stdio.h>
include <conio.h>
define N 20
int fun(float *S,int n,float *aver)
{
/*************found*************/
int ave,t=0;
int count=0,k,i;
for(k=0;k<n;k++)
t+=s[k];
ave=t/n;
for(i=0;i<n;i++)
/*************found***************/
if(s[i]<ave)
count++;
/*************found*************/
aver=ave;
return count;
}
main()
{
float S[30],aver;
int m,i;
clrscr();
printf("\nPlease enter m:");
scanf("%d",&m);
printf("\nPlease enter%d mark:\n",m);
for(i=0;i<m;i++)
scanf("%f",s+i);
printf("\nThe number of students:%d\n",
fun(S,m,&aver));
printf(“AVe=%f\n”,aver);
}
参考答案