I define a function finding the mean value of an array of int, the function is as follows:
float MeanInt(int x[],int num){
float mean, sum = 0.0f,res=0.0f;
int i;
for(i=0;i<num;i++){
sum += (float)(x[i]);
printf("x[%d] is %d\n", i,x[i]);
printf("sum is %f\n", sum);
}
res = sum/((float)(num));
printf("mean should be %f\n", res);
return res;
}
the printf() within this function all works correctly.
The problem is that when I use it in my project, like follows:
printf("mean number is %f\n", MeanInt(ls_tr_acl,num_round));
I meet with an error saying that:
format %f expects argument of type double, but argument 2 has type int
I'm fully confused because the printf() within the function MeanInt() print out exactly the correct result. I also test MeanInt() on some toy examples and it always works correctly. The problem only happens when I run it in my project.