#include <stdlib.h>
#define M 4
#define N 16
int maxi[M];
int mini[M];
int src[N];
int _tmain(int argc, _TCHAR* argv[])
{
int i,j,n;
double avr = 0;
int range_max = +32768;
int range_min = -32768;
for (n = 0; n < N; n++) src[n] = (int)((double)rand()/(RAND_MAX + 1)*(range_max - range_min) + range_min);
for (n = 0; n < N; n++)
{
if (src[n] < mini[0])
{
for (i = M-1; 0 <= i; i--)
{
if (src[n] < mini[i])
{
avr += mini[0];
for (j = 0; j < i; j++) mini[j] = mini[j+1];
mini[i] = src[n];
break;
}
}
}
else if (src[n] > maxi[0])
{
for (i = M-1; 0 <= i; i--)
{
if (src[n] > maxi[i])
{
avr += maxi[0];
for (j = 0; j < i; j++) maxi[j] = maxi[j+1];
maxi[i] = src[n];
break;
}
}
}
else avr += src[n];
}
avr = avr / (N - M*2);
for (n = 0; n < N; n++) printf("src[%02d] = %6d;\n",n,src[n]);
printf("\n");
for (n = M-1; 0 <= n; n--) printf("maxi[%d] = %6d;\n",n,maxi[n]);
printf("\n");
for (n = 0; n < M; n++) printf("mini[%d] = %6d;\n",n,mini[n]);
printf("\n");
printf("avr = %f\n", avr);
return 0;
}