编程计算数组元素的平均值并输出
#include <拿好尘stdio.h>袜仔
int main(int argc, char *argv[])
{
int a[5] = {2, 4, 5, 6, 7};
int i = 0, tmp = 0;
float result = 0;
for(i=0; i<5; i++)
{
tmp = a[i] + tmp;
}
result = tmp/5;
printf("result = %f\n", result);
return 0;
}
结果:消禅
result = 4.000000