111
作者:互联网
111: date:2021.2.4
要点: so easy ! 这次下意识注意到了ave是double型,修改了sum的类型,并做了强转
详细代码如下:
#include <stdio.h>
#pragma warning (disable:4996)
#define N 8
int fun(int x[],double *ave)
{
/* analyse:
统计x数组中偶数的个数;
计算偶数的平均值并存放到ave中;
*/
int i,k = 0;
double sum = 0.0;
for(i = 0; i < N; i++)
{
if(x[i] % 2 == 0)
{
sum += x[i];
k++;
}
}
*ave = sum / (double)k;
return k;
}
main()
{ int x[N]={ 12,5,9,8,23,4,7,21 }, n;
double ave;
void NONO();
n=fun(x,&ave);
printf("n=%d,ave=%lf\n",n,ave);
NONO();
}
标签:int,double,sum,NONO,111,ave 来源: https://blog.csdn.net/weixin_44856544/article/details/113666941