Instruction
1
Record given numeric sequence. Follow her ascending. In the set from left to right the numbers must be from smallest to largest.
2
If the number contains an odd number of numbers, the median should take the value exactly in the middle of the set. For example, a numeric sequence: 400 250 640 700 900 100 300 170 550. In this set the numbers are not in order. After sort in ascending order so we get the following number: 100 170 250 300 400 550 640 700 900. As can be seen, the sequence consists of 9 values. The median of the numerical set in this case will be number 400. From his position on one side all numbers are more median, and on the other – not less.
3
When considering the values of the even-numbered sequence, the Central will be not one but two numbers: m and k. Find these numbers also after arranging the set in ascending order. The median of this case will be the average of the data rate values. Calculate it by the formula (m + k)/2. For example, in the sorted series 200 400 600 4000 30000 50000 number 600 and 4000 occupy a Central position. Therefore, the median of a numerical sequence will be the following value: (600 + 4000)/2 = 2300.
4
If the value set contains a large amount of data manually is rather difficult to sort and determine the center of the range. Using a small program you can easily find the median of a sequence of numbers of any dimension. Example code in Pascal:
var M_ss: array[1..200] of integer;
med: real;
k, i, j: integer;
begin
(*Sort the numbers in ascending order*)
for j:=1 to 200-1 do
for i:=1 to 200-j do
begin
if M_ss[i] > M_ss[i+1] then
k:=M[i];
M_ss[i]:=M_ss[i+1];
M_ss[i+1]=k;
end;
(*Finding the median*)
if (length(M_ss) mod 2)=0 then
med:=( M_ss[trunc(length(M_ss))] + M_ss[trunc(length(M_ss))+1])/2
else
med:=M_ss[trunc(length(M_ss))];
end.
Med in a variable contains the median value of the specified numeric array M_ss.