//计算并输出给定10个数的方差。

 #include<math.h>
#include<stdio.h>
double fun(double x[])
{
double p = 0.0,f=0.0,g=0.0;
for (int i = ; i < ; i++)
{
p += x[i];
}
p = p / ;
printf("%f\n", p);
for (int j = ; j < ; j++)
{
g = x[j] - p;
f += g*g;
printf("%f\n", f);
}
f = f / ;
f = sqrt(f);
return f;
}
void main()
{
FILE *wf;
double s,x[]={95.0,89.0,76.0,65.0,88.0,72.0,85.0,81.0,90.0,56.0};
int i;
printf("\nThe original data is:\n");
for(i=;i<;i++)
printf("%6.1f ",x[i]);
printf("\n\n ");
s=fun(x);
printf("s=%f\n\n ",s);
/******************************/
wf=fopen("out.dat","w");
fprintf(wf,"%f",s);
fclose(wf);
/*****************************/
}
05-14 00:57