QianShengXi
Magic~笑颜常开
采纳率75%
2020-06-12 12:20

各位大佬帮忙看看这段求标准化和标准方差哪里出问题了?

已采纳

想请各位帮忙看看这段代码如何求标准化数据和标准方差,运行出来结果一堆乱数字

#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);

}

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • qiu_shaofeng qiu_shaofeng 10月前

    printf("%3d %6.2f %8.4f %8.4f\n");输出的变量呢

    点赞 1 评论 复制链接分享