関数calculate_median マニュアル

(The documentation of function calculate_median)

Last Update: 2026/1/28


◆機能・用途(Purpose)

実数値配列の要素の中間値を計算する。
Calculate the median of the components of an array of real numbers.


◆形式(Format)

#include <statistics.h>
inline double calculate_median(const int N,const double ∗d)


◆引数(Arguments)

N データサンプル数\(N\)。
The number of data samples \(N\).
d \(N\)個の実数値を並べた配列。
An array composed of \(N\) real numbers.


◆戻り値(Return value)

引数dで与えた実数値配列の要素の中間値。
The median of the array components given by argument d.


◆使用例(Example)

const double d1[]={1.2,34.5,6.78,90.1,2.3};
const double d2[]={-2.3,4.5,-6.7,8.9};
double m1=calculate_median(5,d1);
double m2=calculate_median(4,d2);


◆検証(Validation)

上の「使用例」の計算をこの関数を用いて行い、 正しい結果(\(m1=6.78\), \(m2=(-2.3+4.5)/2=1.1\))が得られることを確認した。
A calculation of the “Example” above using this function yielded correct results (\(m1=6.78\), \(m2=(-2.3+4.5)/2=1.1\)).