Title: Find the largest two-dimensional matrix (element and maximum) in a matrix.
1 2 0 3 4
2 3 4 5 1
1 1 5 3 0
The largest of these are:
4 5
5 3
Requirements: (1) write algorithm, (2) Analysis of Time complexity, (3) write key code in C
Analysis:
Just traverse the two-dimensional array and find the largest two-dimensional array, OK.
Implemented as follows:
#include <iostream> using namespace std;
int Max_matrix (int (*array) [5], int maxx, int maxy, int& posi, int& posj) {int max = 0;
int i = 0, j = 0;
while (I < maxx-1) {j = 0; while (J < maxy-1) {int t = Array[i][j] + array[i+1][j] + array[i][j+1]
+ array[i+1][j+1];
if (Max < T) {max = t;
Posi = i;
POSJ = j;
} j + +;
} i + +;
return to Max;
int main () {int a[3][5] = {{1,2,0,3,4}, {2,3,4,5,1}, {1,1,5,3,0}};
int i = 0, j = 0;
int max = Max_matrix (A, 3, 5, I, j); cout << "Max Num:" << Max <<endl;
cout << "Matrix:" << Endl;
cout << A[i][j] << "" << a[i][j+1] << Endl;
cout << A[i+1][j] << "" << a[i+1][j+1] << Endl; }
The output is as follows:
Max Num:17
Matrix
4 5
5 3
Author: csdn Blog hhh3h
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/