m个人的成绩存放在score数组中,请编写函数fun, 它的功能是:将低于平均分的人数作为函数值返回, 将低于平均分的分数放在below所指定的数组中
/1.m个人的成绩存放在score数组中,请编写函数fun,
它的功能是:将低于平均分的人数作为函数值返回,
将低于平均分的分数放在below所指定的数组中。/
#include <stdio.h>
#include <string.h>
int fun(char *score,char *below,int len)
{
int i=0,j=0;
float ave,sum=0.0;
for(i=0;i<len;i++)
sum+=score[i];
ave=sum/len;
for(i=0;i<len;i++)
{
if(score[i]<ave)
below[j++]=score[i];
}
return j;
}
int main(void)
{
char below[100];
char score[100];
int num=0;
printf("plesae input your student number\n");
scanf("%d",&num);
for(int i=0;i<num;i++)
{
printf("please input student's score\n");
scanf("%d",&score[i]);
}
num=fun(score,below,num);
for(int i=0;i<num;i++)
{
printf("%d ",below[i]);
}
}