//计算并输出给定10个数的方差。
1 #include<math.h> 2 #include<stdio.h> 3 double fun(double x[10]) 4 { 5 double p = 0.0,f=0.0,g=0.0; 6 for (int i = 0; i < 10; i++) 7 { 8 p += x[i]; 9 } 10 p = p / 10; 11 printf("%f ", p); 12 for (int j = 0; j < 10; j++) 13 { 14 g = x[j] - p; 15 f += g*g; 16 printf("%f ", f); 17 } 18 f = f / 10; 19 f = sqrt(f); 20 return f; 21 } 22 void main() 23 { 24 FILE *wf; 25 double s,x[10]={95.0,89.0,76.0,65.0,88.0,72.0,85.0,81.0,90.0,56.0}; 26 int i; 27 printf(" The original data is: "); 28 for(i=0;i<10;i++) 29 printf("%6.1f ",x[i]); 30 printf(" "); 31 s=fun(x); 32 printf("s=%f ",s); 33 /******************************/ 34 wf=fopen("out.dat","w"); 35 fprintf(wf,"%f",s); 36 fclose(wf); 37 /*****************************/ 38 }