作业帮 > 综合 > 作业

请用C语言编写一下程序,

来源:学生作业帮 编辑:灵鹊做题网作业帮 分类:综合作业 时间:2024/04/28 07:33:02
请用C语言编写一下程序,
定义一个函数,功能是计算10个学生的成绩中,高于平均成绩的人数,并作为函数返回值.用主函数来调用它,统计10个学生成绩中,高于平均成绩的有多少人?
输出:enter scores:
输入:100.0 80.5 80.5 80.5 90.5 80.5 80.5 90.5 80.5 80.5
输出:the number of students who's Scores were higher than average is :3
注:输入输出语句如下,请参考使用:
printf("enter scores:\n");
scanf("%f",&a[i]);
printf("the number of students who's Scores were higher than average is :%d\n",count);
请用C语言编写一下程序,
#include <stdio.h>
int moreThanAvg(float score[])
{
    int i;
    float sum = 0.0;
    int count = 0;
    for(i=0; i<10; i++)
    {
        sum += score[i];
    }
    for(i=0; i<10; i++)
    {
        if(score[i]>sum*0.1)
        {
            count++;
        }
    }
    return count;
}
int main()
{
    float a[10];
    int i,count;
    printf("enter scores:\n");
    for(i=0; i<10; i++)
    {
        scanf("%f",&a[i]);
    }
    count = moreThanAvg(a);
    printf("the number of students who's Scores were higher than average is :%d\n",count);
    return 0;
}