0

Hi

I am trying to write a function in a program that reads a 2d array withs 2 rows & determines the largest number & whehter that number is in row 0 or row 1.

For example:

Enter distinct integers for a 2d array with 2 rows and 5 columns.

3 1 5 2 4

8 6 9 7 0The maximum is 9 in row 1 and column 2

**How do I determine if the largest number (in this case '9') is in the 1st row or the 2nd & return that into main?**

My coding so far works great at finding the maximum number of the 1st row **but cant return the row its in into main. **

```
#include <iostream>
#include <iomanip>
using namespace std;
// read values for a two-dimentional array
void read2d(int a[][5], int rowsize);
// display the values in a two-dimentional array
void display2d(const int a[][5], int rowsize);
// find the ma and min in 2d array a
void max(int a[][5], int rowsize, int& row, int& col); //this is the function that isn't working
int main()
{
int table[2][5];
int rowIndex, colIndex;
cout << "Enter distinct integers for a 2d array with 2 rows and 5 columns." << endl; // don't modify
read2d(table, 2); // don't modify
display2d(table, 2); // don't modify
max(table, 2, rowIndex, colIndex);
// write code to locate the maximum in 2d array table
cout << "The maximum is " << table[rowIndex][colIndex] << " in row " << rowIndex << " and column " << colIndex << endl; // don't modify
return 0;
}
void read2d(int a[][5], int rowsize)
{
for (int i = 0; i < rowsize; i++)
for (int j = 0; j < 5; j++)
cin >> a[i][j];
}
void display2d(const int a[][5], int rowsize)
{
for(int i = 0; i < rowsize; i++)
{
for(int j = 0; j < 5; j++)
cout << setw(5) << a[i][j];
cout << endl;
}
cout << endl;
}
void max(int a[][5], int rowsize, int& row, int& col)
{
int temp= 0;
int max;
int j= 0;
for (j; j <= 1; j++)
{
for (int i = 0; i <= 5; i++)
{
if (a[j][i] >= temp) {
cout << a[j][i] << endl;
temp = a[j][i];
}
}
}
temp = max;
return a[j][max];
}
```

This is the function not doing what I want it to do; find the maximum & what row it is in.

```
void max(int a[][5], int rowsize, int& row, int& col)
{
int temp= 0;
int max;
int j= 0;
for (j; j <= 1; j++)
{
for (int i = 0; i <= 5; i++)
{
if (a[j][i] >= temp) {
cout << a[j][i] << endl;
temp = a[j][i];
}
}
}
temp = max;
return a[j][max];
}
```