C++ Program to Find Largest and Second Largest Number in 2D Array

Here is the C++ program to find largest and second largest number in a 2d array or matrix.

Output

Enter no of rows and columns(max 5):3
3
Enter the array:
4 6 8
2 4 6
2 12 5
Largest number:12
Second largest number:8

5 thoughts on “C++ Program to Find Largest and Second Largest Number in 2D Array

  1. John Smiles

    i would like to see thhis solution

    find the maximum element in even rows of a matrix using C++ programming.

    thank you

    Reply
  2. athirsta

    above code doesn’t work for this input
    2*2
    4 3
    2 1
    prints 4 for both

    Reply
    1. Admin Post author

      There was a little mistake in code, I have corrected it, now working fine. Thanks for mentioning the mistake.

      Reply
  3. NAWAL

    how to also tell the user the index of row and column at which maximum number is found?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *