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

问题描述:

请用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);
1个回答 分类:综合 2014-10-02

问题解答:

我来补答
#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;
}
 
 
展开全文阅读
剩余:2000