# Untitled

user_9831585
plain_text
a year ago
1.5 kB
6
Indexable
Never
```#include <iostream>

using namespace std;

void findMaxSubMatrix(int matrix[][5], int &startRow, int &startColumn, int &subRows, int &subColumns, int &sum)
{
int maxSum = 0;

for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
for (int k = i; k < 5; k++)
{
for (int l = j; l < 5; l++)
{
int currentSum = 0;

for (int m = i; m <= k; m++)
{
for (int n = j; n <= l; n++)
{
currentSum += matrix[m][n];
}
}

if (currentSum == 0 && (k - i + 1) * (l - j + 1) > maxSum)
{
maxSum = (k - i + 1) * (l - j + 1);
startRow = i;
startColumn = j;
subRows = k - i + 1;
subColumns = l - j + 1;
sum = currentSum;
}
}
}
}
}
}

int main()
{
int matrix[5][5];
int startRow, startColumn, subRows, subColumns, sum;

cout << "Enter elements of the matrix: " << endl;
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
cin >> matrix[i][j];
}
}

findMaxSubMatrix(matrix, startRow, startColumn, subRows, subColumns, sum);

cout << "Maximum sub-matrix with only zeros starts at (" << startRow << ", " << startColumn << ") and has " << subRows << " rows and " << subColumns << " columns and has a sum of " << sum << "." << endl;

return 0;```