# Answer to Question #21974 in C++ for rodea embradura

Question #21974

the median of a set of integers is the value which divides the set exactly in half. Given a one-dimensional array whose elements are sorted from lowest to highest, the median can be determined by applying the ff. rules:

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.

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.

Expert's answer

#include <conio.h>

#include <iostream>

using namespace std;

void main()

{

int array[10];

float median;

/* 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[5] + array[4]) / 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;

getch();

}

#include <iostream>

using namespace std;

void main()

{

int array[10];

float median;

/* 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[5] + array[4]) / 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;

getch();

}

Need a fast expert's response?

Submit orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

## Leave a comment