For example
[1, 2, 3, 4, 5, 6
4, 5, 6, 7, 8, 9
2, 3, 4, 5, 6, 7
3, 4, 5, 6, 7, 8
5, 6, 7, 8, 9, 10
0, 1, 2, 3, 4, 5]
Decomposed into nine small matrices of 2*2
[[[[[[[[[]
]
# Include "iostream"
Using namespace STD;
# Define side_length 2 // specify the length and width of the square matrix.
# Define height 6 // The length of the original matrix
# Define width 6 // width of the original matrix
Void print (int * buffer, int length );
Void main ()
{
Int I, J, K, T;
Int matrix [height] [width] =, }, {, 9, 10 }};
Int * minimatrix;
Int h_num = height/side_length; // number of segments separated by a small matrix in the long and wide directions
Int w_num = width/side_length;
Minimatrix = new int [side_length * side_length];
Cout <"the original matrix is:" <Endl;
For (I = 0; I {
For (j = 0; j <width; j ++)
{
Cout <matrix [I] [J] <"";
}
Cout <Endl;
}
For (I = 0; I {
For (j = 0; j <w_num; j ++)
{
For (k = 0; k <side_length; k ++)
{
For (t = 0; t <side_length; t ++)
{
* (Minimatrix + K * side_length + T) = matrix [I * side_length + k] [J * side_length + T];
}
}
Print (minimatrix, side_length); // display the split small matrix.
}
}
}
// Display function
Void print (int * buffer, int length)
{
Int M, N;
Int num = 1;
Cout <num <"minimatrix is:" <Endl;
For (m = 0; m <length; m ++)
{
For (n = 0; n <length; n ++)
{
Cout <* (buffer + M * Length + n) <"";
}
Cout <Endl;
}
Num ++;
}