### 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.
 ``1234567891011121314151617181920212223242526272829303132333435363738`` ``````#include #include 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<
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:
 ``12`` ``````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:
 ``123456`` ``````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.