[Solved] : Question 12766

float Median;

for (int j = 0; j < m; j++)
{
for (int i = 0; i < j; i++)
{
if (array[j] < array[i])
{
int temp = array[j][i];
array[j][i] = array[i][j];
array[i][j] = temp;
}
}
}

for (int j = 0; j < m; j++)
{
if (n % 2 == 0)
{
int i = 0;
Median = ((array[i][j]/2) + (array[i][j]/2)-1)/2;
cout << Median << endl;
}

if (n % 2 != 0)
{
int i = 0;
Median = array[i][j]/2;
cout << Median << “nn”;
}
}
cout << “The Median of each row is displayed above.nn”;
}

}
return 0;
}

I have been having lots of trouble trying to get the Median of each row in a 2D array. Note that m is the variable that represents the length of a row and n is the variable that represents the length of a column. The user had chose these variables earlier in the program. Also note that array[i][j] was what stored the lengths as well as the numbers the user wanted to put in the matrix. This is also earlier in the program. If I wanted to find the median of each row starting with row 1 and going to row m, how would I go about that?


Expert Answer


Answer to : Question 12766

Leave a Comment

About

We are the best freelance writing portal. Looking for online writing, editing or proofreading jobs? We have plenty of writing assignments to handle.

Quick Links

Browse Solutions

Place Order

About Us

× How can I help you?