本帖最后由 jhq999 于 2021-11-19 12:55 编辑 double GetVal(double invals[],int count )
{
int i=0,j=0,flag=1;
double sum=0,tmp=0;
for(i=0;i<count;i++)
{
flag=1;
for(j=0;j<count-i;j++)
{
if(0==i)sum+=invals[j];
if(invals[j]<invals[j-1])
{
flag=0;
tmp=invals[j-1];invals[j-1]=invals[j];invals[j]=tmp;
}
}
if(flag)break;
}
return sum/(double)count;
}
double GetVal(double invals[],int count,bool isoddnum)
{
if(isoddnum)return invals[count/2+1];
return ( invals[count/2-1]+ invals[count/2])/2;
}
void GetVal(double invals[],int count,double outvals[] )
{
outvals[2]=GetVal(invals,count);
outvals[0]=invals[0];
outvals[1]=invals[count-1];
outvals[3]=GetVal(invals,count,count%2);
}
int main()
{
double a[]={6,2,4,3,4,7,1,5},b[4]={0};
GetVal(a,sizeof(a)/sizeof(double),b);
printf("最小:%.2lf",b[0]);
printf("最大:%.2lf",b[1]);
printf("平均值:%.2lf",b[2]);
printf("中值:%.2lf",b[3]);
return 0;
}
|