Averages/Median: Difference between revisions

Content added Content deleted
(→‎{{header|Fortran}}: Using a supplied routine...)
Line 1,275: Line 1,275:
end program Median_Test</lang>
end program Median_Test</lang>


If one refers to [[Quickselect_algorithm#Fortran]] which offers function FINDELEMENT(K,A,N) that returns the value of A(K) when the array of N elements has been rearranged if necessary so that A(K) is the K'th in order, then, <lang Fortran> K = N/2
If one refers to [[Quickselect_algorithm#Fortran]] which offers function FINDELEMENT(K,A,N) that returns the value of A(K) when the array of N elements has been rearranged if necessary so that A(K) is the K'th in order, then, supposing that a version is devised using the appropriate type for array A, <lang Fortran> K = N/2
MEDIAN = FINDELEMENT(K + 1,A,N)
MEDIAN = FINDELEMENT(K + 1,A,N)
IF (MOD(N,2).EQ.0) MEDIAN = (FINDELEMENT(K,A,N) + MEDIAN)/2 </lang>
IF (MOD(N,2).EQ.0) MEDIAN = (FINDELEMENT(K,A,N) + MEDIAN)/2 </lang>