Matrix Class - Wrong Outputs?!
https://code.sololearn.com/cq24J951TxgI/# I have the following Matrix Class. Now I tried to create a function to Split the Matrix into Sub-Matrices of size m_r * m_c each and save them in a Matrix of Matrix - Matrix** for easy access... friend Matrix** Split(Matrix m,int m_r,int m_c) { if((m.r%m_r==0)&&(m.c%m_c==0)&&(m_r<m.r)&&(m_c<m.c)) { int new_r=m.r/m_r; int new_c=m.c/m_c; Matrix** matrix=new Matrix*[new_r]; for(int i=0;i<new_r;i++) { matrix[i]=new Matrix[new_c]; for(int j=0;j<new_c;j++) matrix[i][j].Reset(m_r,m_c); } for(int i=0;i<m.r-m_r;i++) { for(int j=0;j<m.c-m_c;j++) { for(int k=0;k<m_r;k++) { for(int l=0;l<m_c;l++) { matrix[i][j].mat[k][l]=m.mat[i+k][j+l]; } } } } return matrix; } else { //Do Something else. } } Now, the problem is that the outputs are wrong. Eg - When Input - 1 1 0 0 1 1 0 0 0 0 1 1 0 0 1 1 Output - 1 1 1 1 // Correct 1 0 0 0 1 0 //Wrong 0 0 1 1 0 0 0 0 //Wrong 0 0 1 0 1 1 0 1 //Wrong 1 1 Why is the output wrong? P.S. - I tried Increasing the limits of i and j's loop by 1, but that stops the program.