#include <stdio.h>
#include<stdlib.h>
#include<time.h>
int middle(float *b,int m)
{
int j,k;
float t;
float temp;
float *c[m];
for(j=0;j<m;j++)
{
c[j]=&b[j];
}
for(j=0;j<=m-1;j++)
{
for(k=j+1;k<m;k++)
{
if(*c[j]>*c[k])
{
temp=*c[j];
*c[j]=*c[k];
*c[k]=temp;
}
temp=0;
}
}
printf("排序后的结果为:\n");
for(j=0;j<m;j++)
{
printf("%.0f ",*c[j]);
}
if (m%2==1)
{
printf("\n此时中位数为:%.0f",*c[(m-1)/2]);
}
else if(m%2==0)
{
printf("此时中位数为:%.2f",(*c[m/2]+*c[(m-1)/2])/2);
}
return 0;
}
int main () {
int i;
srand((unsigned int )time(NULL));
int n=rand()%10+2;
printf("随机生成的数组大小为:%d",n);
float *a=malloc(n*4);
printf("随机生成的数组为:\n");
for(i=0;i<n;i++)
{
a[i]=rand()%10+1;
printf("%.0f ",a[i]);
}
printf ("\n");
middle(a,n);
return 0;
}