求组C大神,两个程序和在一起,可以自己计算平均值又可以显示方差和标准差
#include "stdio.h"#include "math.h"
#define N 100
void main()
{
int a[N],n,i;
float aver,s;
float sum=0,e=0;
printf("请输入样本量:");
scanf("%d",&n);
printf("请输入%d个样本:",n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
aver=sum/n;
for(i=0;i<n;i++)
e+=(a[i]-aver)*(a[i]-aver);
e/=n-1;
s=sqrt(e);
printf("平均数为:%.2f,方差为:%.2f,标准差为:%.2f\n",aver,e,s);
}
#include <stdio.h>
void main()
{
int a[15]={355,345,365,343,354,367,383,521,120,354,345,367,356,348,350};
int i,max,min,sum;
double average;
sum=0;
max=a[0];
min=a[0];
for(i=0;i<15;i++)
{
if(max<a[i])
max=a[i];
if(min>a[i])
min=a[i];
sum=sum+a[i];
}
average=(double)(sum-max-min)/13;
printf("\nThe max=%d\n",max);
printf("\nThe min=%d\n",min);
printf("\nThe average is:%f\n",average);
printf("\n");
}