/1.m个人的成绩存放在score数组中,请编写函数fun,
它的功能是:将低于平均分的人数作为函数值返回,
将低于平均分的分数放在below所指1定的数组中。/
#include <stdio.h>
#include <string.h>
int fun(int *buf, int *buff, int num)
{
int i = 0, j = 0, sum = 0;
for (i = 0; i < num; i++)
sum += buf[i];
float ave = sum / num;
for (i = 0; i < num; i++)
{
if (buf[i] < ave)
buff[j++] = buf[i];
}
return j;
}
int main(void)
{
int below[100];
int score[100];
int num = 0, n;
printf("请输入多少人\n");
scanf("%d", &num);
printf("请输入每个人的成绩\n");
for (int i = 0; i < num; i++)
scanf("%d", &score[i]);
n = fun(score, below, num);
for (int i = 0; i < n; i++)
printf("%d\n", below[i]);
return 0;
}
标签:num,函数,int,++,below,score,数组,平均分
From: https://www.cnblogs.com/yesiming/p/18019551