输入某班学生某门课的成绩(最多不超过40人),
当输入为负值时,表示输入结束,
用函数编程统计成绩不低于平均分的学生人数。
要求:
(1)按如下函数原型进行编程:
int GetAboveAver(int score[], int n);
(2)在主函数中:
输入学生成绩,
然后调用函数GetAboveAver计算成绩不低于平均分的学生人数,
最后输出该人数。
要求:
(1)学生成绩和平均分均定义为int类型
(2)**无输入提示信息
**输入格式为:"%d"
**输出格式为:"Students of above average is %d\n"
#include <stdio.h>
void main( )
{
int str[40];
int i = -1, aver = 0, a, b = 0, c = 0;
do
{
i++;
scanf("%d", str[i]);
}
while (str[i] > 0);
for (a = 0; a < i; a++)
aver += str[a];
aver = aver / (i-1);
while (b < i)
{
if (str[b] >= aver)
c++;
b++;
}
printf("Students of above average is %d\n", c);
}