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();
}