编写函数,求包含n个元素的整数数组中元素的平均值。要求在函数内部使用指针操纵数组元素,其中n个整数从键盘输入,输出为其平均值。
样例输入: (输入格式说明:5为输入数据的个数,3 4 0 0 2 是以空格隔开的5个整数)5 3 4 0 0 2样例输出:1
样例输入: 73 2 7 5 2 9 1样例输出:4
#include<stdio.h>
int main(){
int n;
scanf("%d",&n);
int i,a[n],ave=0;
for(i=0;i<n;i++){
scanf("%d",&a[i]);
ave+=a[i];//no ave+=a[i]/n;
}
printf("%d",ave/n);
return 0;
}
转载请注明原文地址: https://ju.6miu.com/read-10748.html