09/01/07 13:38:33
>>326
#include <stdio.h>
int median(int *in, int num)
{
int i, j, temp;
for(i=num-1; i > 0; i--) {
for(j=0; j<i; j++) {
if(in[i] > in[j]) {
temp = in[i];
in[i] = in[j];
in[j] = temp;
}}}
return num & 1 ? in[num/2] : (in[num/2-1] + in[num/2]) / 2;
}
int main(void)
{
int i, num, in[128];
scanf("%d", &num);
for(i=0; i<num; i++) scanf("%d", in + i);
printf("%d", median(in, num));
return 0;
}