一、运行结果;
二、源代码;
# define _CRT_SECURE_NO_WARNINGS
# include <stdio.h>
//声明平均数函数average;
float average(float score[10]);
int main()
{
//初始化变量值;
float score[10], aver;
int i = 0;
//填充数组;
printf("请输入10名学生成绩\n");
for (i = 0; i < 10; i++)
{
//获取;
printf("第%d个学生成绩为:", i + 1);
scanf("%f", &score[i]);
}
//调用平均函数;
aver = average(score);
//输出;
printf("10名学生成绩的平均值为:%.2f", aver);
return 0;
}
//实现average函数;
float average(float score[10])
{
//初始化变量值;
float sum = 0;
int i = 0;
//赋值;
sum = score[0];
//循环相加;
for (i = 1; i < 10; i++)
{
//相加;
sum = sum + score[i];
}
//求平均数;
return (sum / 10);
}