Answer to Question #21974 in C++ for rodea embradura
a) if the number of elements in the array is odd, the element in the middle of the array is the median.
b) if the number of elements in the array is even, the median is computed as the average of the 2 middle elements.
Write a program that will accept the number of 10 elements in the array and the data elements as inputs. Display the array's elements along with the median.
using namespace std;
/* Input array elements */
cout << "Enter 10 array elements sorted from lowest to highest." << endl;
for (int c = 0; c < 10; c++)
cin >> array[c];
cout << endl;
/* Calculate the median */
median = (array + array) / 2;
/* Output the array */
cout << "Array elements:" << endl;
for (int u = 0; u < 10; u++)
cout << array[u] << ' ';
cout << endl << endl;
/* Display the median */
cout << "The median is: " << median << endl;
Need a fast expert's response?Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!