- Today I only did a meaningful thing,which was a mathermatic speech.
- The Data scientist is an old man(Tugluk·Abdurajak),he is so amiable. Thanks for his speech.
- It took me two and half hours ,but it's worth watching.
#include<stdio.h>
#include<math.h>
int main()
{
double s = 0, s1=0, x[10];
printf("Please input 10 numbers:\n");
for (int i = 0; i < 10; i++)
{
scanf("%f", &x[i]);
s1 += x[i];
}
s1 = s1 / 10;
for (int i = 0; i < 10; i++)
{
s = s + ((x[i]-s1) *( x[i]-s1));
}
s = s / 10;
s = pow(s, 0.5);
printf("The Variance is %lf", s);
return 0;
}
The only failure there is is the failure to try
这好像是总体标准偏差,并不是方差(Variance),方差不开根号的
你的
scanf
中的格式符有点问题scanf
中lf对应double *
,用f会降级为float *
的,精度有可能会丢失不过
printf
中就随便了,默认按double
输出参考scanf, fscanf, sscanf, scanf_s, fscanf_s, sscanf_s - cppreference.com