Finding the min, max, average, median of an array set?

I'm doing a homework assignment for school, and our current assignment is to find the minimum number, max number, average of numbers and medians of numbers in an array. The array is defined by user input.
I have code to get the user input and to sort the array, but I'm stuck on exactly how to pick out the individual array values for a min or max. I could imagine that finding an average is easier than I believe it to be, but I'm honestly not sure how to do it. Same for median.
Thanks for any 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
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int *array, min=0, temp;
	array = new int[20];
	for(int x = 0; x < 20; x ++) //For loop asks user input 20 times.
	{
    cout << "Enter number " << x << ": " << endl;
    cin >> array[x];
	}
	for (int x = 0 ; x < 20; x++) //For loop displays user input 20 times.
	{
		cout<<array[x]<<endl; 
	}
	
	for(int i=0; i<10; i++) //Sorts the values in ascending order (high to low)
	{
  	for(int y=0; y<9; y++)
  	{
   		if (array[y]<array[y+1])  
   		{
   	 		temp=array[y+1]; //This is where the actual sorting happens
   	 		array[y+1]=array[y];
   	 		array[y]=temp;
			}
  	} 
	}
	for (int i=0; i<10; i++) //Displays new contents to confirm sucessful sorting
	{ 
    cout << array[i] << endl;
	}
cout<<endl;
	return 0;
	
}
So I didn't inspect your code but if it correctly sorts the array into ascending order then to find the min and max is simple:
1
2
min = array[0];  // The first element in the array
max = array[19];  // The last element in the array since the size is 20 


To find the average is pretty simple as well:
1
2
3
4
5
6
int sum = 0, average;
for(int i = 0; i < 20; i++)
{
    sum += array[i];
}
average = sum/20;  // This is an int so it will 'round' down 
Figures. I always over complicate this sort of thing.
What about finding the median? If there's an even set of numbers, would I take the average of array[9] and array[10] to find the median of the set?
Topic archived. No new replies allowed.