0

Hi I am sort of having a little trouble with a part of my program. First off let me tell you a couple of the variables. Let m be the number of rows and let n be the number of columns in a 2D array. Let i be the counter for row m and j be the counter for column n. Let spreadsheet[i][j] contain the matrix with dimensions m and n that the user chose. This matrix is populated with numbers. If the user was asked to choose a row they would like to find the Median of, how would I go about that? My attempt:

`float Median;

```
for (int j = 0; j < n; j++)
{
for (int k = 0; k < j; k++)
{
if (spreadsheet[i][j] < spreadsheet[j][k])
{
int temp = spreadsheet[i][j];
spreadsheet[i][j] = spreadsheet[j][k];
spreadsheet[j][k] = temp;
}
}
}
if (n % 2 == 0)
{
for (int j = 0; j < n; j++)
Median = ((spreadsheet[i-1][j]/2) + (spreadsheet[i-1][j]/2)-1)/2;
cout << "The Median of row " << i << " = " << Median << ".\n";
}
if (n % 2 != 0)
{
for (int j = 0; j < n; j++)
Median = spreadsheet[i-1][j]/n;
cout << "The Median of row " << i << " = " << Median << ".\n";
}`
```