my professor has asked us to solve the following problem but im having trouble understanding it

**Write a function that takes in a 2 dimensional array of integers and returns the third largest
number. Let the number of columns of your 2 dimensional array be 5. Call this function from
the main program with 2 different arrays to show that it works.
**

Ive tried to make sense of it and create a code but i am not sure how to call the function in the main function. i tried to create a variable int a[][5], which gave me an error saying that that the first bracket can't be empty. He doesn't specify the number of rows, so should it be 1, by default?

I am trying to understand a function he used in class as example. This was a code to find the second maximum class which is

int SecondMax2D(int a[][5], int rows)
{
    int max1;
    int max2;


    if (a[0][0]>a[0][1])
    {
        max1= a[0][0];
        max2=a[0][1];
    }
    else
    {
        max1=a[0][1];
        max2=a[0][0];
    }

    for (int row=0; row<rows; row++)
    {   
        for (int col=0; col<10; col++)
        {   
            if(row = = 0 && (col == 0 || col ==1))
                continue;
            if (a[row][col]> max1)
            {
                max2=max1;
                max1=a[row][col];
            }
            else if (a[row][col]>max2)
                max2=a[row][col];
        }

    }

    return max2;
}

I am not quite sure what int rows is supposed to be. isnt a[] supposed to be the number of rows?

If wanted to call this function in the main function, how would i do it?

 int main()
    {


        SecondMax2d(__, ___,___) 
        // If he gives a question(similar to the one above) where he says it should have 10 columns, without specifying rows, i am not sure what's supposed to go in the first blank, and the last, which is supposed to be int rows. 




    system("pause");
    return 0;

    }

Thanks for your help

i've modified my code with the following, however im getting an error when i debug it, it freezes and says," Unhandled exception at 0x779415de in 2darray.exe: 0xC0000005: Access violation reading location 0x00000000."

#include <iostream>

using namespace std;


int SecondMax2D(int a[2][5], int rows)
{
    int max1;
    int max2;


    if (a[0][0]>a[0][1])
    {
        max1= a[0][0];
        max2=a[0][1];
    }
    else
    {
        max1=a[0][1];
        max2=a[0][0];
    }

    for (int row=0; row<rows; row++)
    {   
        for (int col=0; col<10; col++)
        {   
            if(row == 0 && (col == 0 || col ==1))
                continue;
            if (a[row][col]> max1)
            {
                max2=max1;
                max1=a[row][col];
            }
            else if (a[row][col]>max2)
                max2=a[row][col];
        }

    }

    return max2;
}
int main()
{
    int a[2][5]={{34,2,33,45,12},{7,58,46,23,5}};


    cout<< SecondMax2D(0, 2); ;



system("pause");
return 0;

}

line 47 : at your function call your not using the array as your first parameter

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.