#include <stdio.h>
#include <stdlib.h>
int median(int a[], int n) {
int i;
int j;
int k;
int t;
int c;
k = n - 1;
c = k >> 1;
while (c <= k) {
i = -1;
for (j = 0; j < k; j++) {
if (a[j + 1] < a[j]) {
t = a[j];
a[j] = a[j + 1];
a[j + 1] = t;
i = j;
}
}
k = i;
}
return a[c];
}
int main(void) {
int a[7];
int c = 7;
int i;
for (i = 0; i < c; i++) {
printf("%d番目の数字を入力してください: ", i
+ 1); }
printf("中央値は %d です。\n", median
(a
, c
));
return EXIT_SUCCESS;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCmludCBtZWRpYW4oaW50IGFbXSwgaW50IG4pIHsKICBpbnQgaTsKICBpbnQgajsKICBpbnQgazsKICBpbnQgdDsKICBpbnQgYzsKICAKICBrID0gbiAtIDE7CiAgYyA9IGsgPj4gMTsKICB3aGlsZSAoYyA8PSBrKSB7CiAgICBpID0gLTE7CiAgICBmb3IgKGogPSAwOyBqIDwgazsgaisrKSB7CiAgICAgIGlmIChhW2ogKyAxXSA8IGFbal0pIHsKICAgICAgICB0ID0gYVtqXTsKICAgICAgICBhW2pdID0gYVtqICsgMV07CiAgICAgICAgYVtqICsgMV0gPSB0OwogICAgICAgIGkgPSBqOwogICAgICB9CiAgICB9CiAgICBrID0gaTsKICB9CiAgCiAgcmV0dXJuIGFbY107Cn0KCmludCBtYWluKHZvaWQpIHsKICBpbnQgYVs3XTsKICBpbnQgYyA9IDc7CiAgaW50IGk7CiAgCiAgZm9yIChpID0gMDsgaSA8IGM7IGkrKykgewogICAgcHJpbnRmKCIlZOeVquebruOBruaVsOWtl+OCkuWFpeWKm+OBl+OBpuOBj+OBoOOBleOBhDogIiwgaSArIDEpOwogICAgc2NhbmYoIiVkIiwgJmFbaV0pOwogIH0KICBwcmludGYoIuS4reWkruWApOOBr+OAgCVkIOOBp+OBmeOAglxuIiwgbWVkaWFuKGEsIGMpKTsKICAKICByZXR1cm4gRVhJVF9TVUNDRVNTOwp9