C语言题目:要求用户输入10个学生的考试成绩,并编写一个求平均值的函数,求这10个学生的平均成绩。

如题所述

#include<stdio.h>
float av(int n)
{int i,x,s=0;
 for(i=0;i<n;i++)
 {scanf("%d",&x);
  s+=x;
 }
 return (float)s/n;
}
int main()
{int n;
 float cj;
 printf("请输入10个学生的成绩:\n");
 cj=av(10);
 printf("平均分=%.1f\n",cj);  
 return 0;
}

温馨提示:答案为网友推荐,仅供参考