Input: M[][] = {{1, 2, 3, 4}, {0, 5, 6, 7}, {0, 0, 8, 9}, {0, 0, 0, 10}}
Output: Row-wise: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
Column-wise: {1, 2, 5, 3, 6, 8, 4, 7, 9, 10}
Explanation: All the non-zero elements of the matrix are {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
Input: M[][] = {{1, 2, 3, }, {0, 4, 5}, {0, 0, 6}}
Output: Row-wise: {1, 2, 3, 4, 5, 6}
Column-wise: {1, 2, 4, 3, 5, 6}
Explanation: All the non-zero elements of the matrix are {1, 2, 3, 4, 5, 6}