#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
double Avage(double a[],int n){
double avage = 0;
int i;
for (i=0;i<n;i++){
avage += a[i];
}
avage /=n;
return avage;
}
int main(){
int n,i,r;
scanf("%d",&r);
for(i=1;i<r;i++){
while(scanf("%d",&n)!=EOF){
double a[50],t,s=0;
for(i=0;i<n;i++){
scanf("%lf",&a[i]);
}
for(i=0;i<n;i++){
t=Avage(a,n);
s=s+(a[i]-t)*(a[i]-t);
}
printf("s^2=%.2f\n",s/n);
}
}
return 0;
}
关于方差的代码