想请各位帮忙看看这段代码如何求标准化数据和标准方差,运行出来结果一堆乱数字
#include
#include
int main(void)
{
int i,n,s1,s2,me1,me2,sg;
double x[50],xh[50],y[50];
printf("数据个数n=");
scanf("%d",&n);
for (i = 1;i <= n;i++) {
printf("x[%d]");
scanf("%lf",&x[i]);
}
s1 = 0;
s2 = 0;
for (i = 1;i <= n;i++) {
s1 = s1 + x[i];
s2 = s2 + x[i]*x[i];
}
me1 = s1 / n;
me2 = s2 / n;
sg = sqrt(me2 - me1 * me1);
for (i = 1;i <= n;i++) {
xh[i] = (x[i] - me1) / sg;
y[i] = 10*xh[i] + 50;
}
printf("标准方差:\n");
printf("sg\n");
printf("标准化数据和方差値\n");
printf(" i x[i] xh[i] y[i]\n");
for (i = 1;i <= n;i++) {
printf("%3d %6.2f %8.4f %8.4f\n");
}
return(0);
}