Write a function named flatten, that takes a matrix of integersand their dimensions as the arguments, then returns a 1D array suchthat this array is the “flattened” version of the matrix.Demonstrate the function in the main program. The prototype of thefunction should look like: int* transpose(int** matrix, int nrow,int ncol); Sample input: Sample output: 12 3 1 2 3 4 5 45 6
Answer
int* transpose(int** matrix, const int nrow, const int ncol){ int* result = new int[ncol*nrow]; for(int i = 0;i<nrow;i++){ for(int j = 0;j<ncol;j++){
OR
OR