Need help

A computer program to determine the median.
(a) Maximum
(b) Minimum
(c) Range
(d) Mean
(e ) Standard deviation
(f) Variance
Now I want to locate the median. So most of this code can be deleted. Obviously the 56 numbers will be needed but I need a working code.
Help!!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include<iostream>
#include<cmath>

using namespace std;



int main()
{
const int size=56;
double R[size]={45.3, 67.8, 34.3, 51.2, 48.5, 61.3, 59.3, 65.1,
49.3, 42.4, 63.5, 69.8, 71.2, 39.8, 55.5, 53.2,
56.7, 48.8, 61.5, 51.2, 58.9, 63.1, 67.5, 62.4,
52.4, 50.2, 49.8, 56.8, 59.7, 60.4, 45.8, 43.8,
51.3, 54.8, 55.1, 52.3, 56.2, 59.7, 63.0, 46.7,
63.1, 58.2, 41.9, 59.2, 57.2, 67.3, 68.2, 38.9,
51.3, 63.8, 53.4, 58.9, 56.3, 58.9, 53.2, 56.8},
sum=0, mean, max=0, min=100, range, sum1, variance, std;

// Find average
for(int count=0; count<=size-1; count++)
{
sum=sum+R[count];
//cout<<sum<<" ";

//Find Maximum
if (R[count]> max)
{
max=R[count];
}

//Find Minimum



}
mean=sum/size;
range= ;


// Find the variance and standard devisation

for (int i=0; i<=size-1; i++)
{
sum1=sum1+( )*( );

}

variance=
std=sqrt(variance);





cout<<"The mean is "<<mean<<endl;
cout<<"The maximum is "<<max<<endl;






//cout<<"R[55]= "<<R[size-1]<<endl;


system("pause");
return 0;
}
Last edited on
The median is just the middle observation of an ordered list.

You'll need to write an algorithm that sorts the array into ascending order. Then, you'd pretty much need to pick the middle element.

That said, you have an even number in your array (56), so you'll have to work out the mean of the two middle values in order to work out the median.
How can i do it, i am stuck can you help me figure this out
First things first, you need to sort the numbers.

You can write your own implementation of a sort algorithm, looping through the array and sorting them appropriately (there are a bunch of ways of doing this, Google: sort algorithm).

Alternatively, you can use the standard algorithm.
http://www.cplusplus.com/reference/algorithm/sort/
Topic archived. No new replies allowed.