#include
#include
float Add(float a1,float a2,float a3,float a4,float a5,float a6,float as);
int main()
{
float R1=2682.0,R2=2680.0,R3=2681.4,R4=2680.7,R5=2682.0,R6=2680.9,Rs;
float Uas,Ubs,Ucs,Ua1,Ub1,Uc1,Ucx,U;
Rs=(R1+R2+R3+R4+R5+R6)/6;
Uas=sqrt((1/30)*Add(R1,R2,R3,R4,R5,R6,Rs));
printf("Rs=%f,Uas=%f",Rs,Uas);
return 0;
}
float Add(float a1,float a2,float a3,float a4,float a5,float a6,float as)
{
float b[6]={a1,a2,a3,a4,a5,a6};
float x=0;
int i;
for(i=0;i<6;i++){
x+=(b[i]-as)*(b[i]-as);
}
return x;
}
没有报错但是最终Rs有值,Uas值为0,想知道哪里写错了
11行改成:
Uas = sqrt((1.0 / 30.0)*Add(R1, R2, R3, R4, R5, R6, Rs));
11行那里Uas = sqrt((1/ 30)*Add(R1, R2, R3, R4, R5, R6, Rs));改为:
Uas = sqrt((1.0 / 30)*Add(R1, R2, R3, R4, R5, R6, Rs));
因为整型/整型还是整型,所以1/30会是0,所以我们要改成1.0/30 这样就不会是0了