以下のコードをenthusiasticgeekから変更して、ユーザー入力(たとえば、入力n、次にn個の整数)を許可する方法を知っている人はいますか?これらのn個の整数と中央値を出力します。nは奇数で正であり、100万未満です。
enthusiasticgeek.comから貼り付けられたコード:
#include <stdio.h>
#include <stdlib.h>
#define ELEMENTS 6
int values[] = { 40, 10, 100, 90, 20, 25 };
int compare (const void * a, const void * b)
{
return ( *(int*)a - *(int*)b );
}
int main ()
{
int n;
qsort (values, ELEMENTS, sizeof(int), compare);
for (n=0; n<ELEMENTS; n++)
{ printf ("%d ",values[n]); }
printf ("median=%d ",values[ELEMENTS/2]);
return 0;
}