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.
1
Expert's answer
2013-01-17T09:43:09-0500
#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(); }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment