Question

Write a function named flatten, that takes a matrix of integers and their dimensions as the...

Write a function named flatten, that takes a matrix of integers and their dimensions as the arguments, then returns a 1D array such that this array is the “flattened” version of the matrix. Demonstrate the function in the main program. The prototype of the function should look like: int* transpose(int** matrix, int nrow, int ncol); Sample input: Sample output: 12 3 1 2 3 4 5 45 6

0 0
Add a comment Improve this question Transcribed image text
Answer #1
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++){
          result[i*nrow+j] = matrix[i][j];
      }
   }
   return result;
}
Add a comment
Know the answer?
Add Answer to:
Write a function named flatten, that takes a matrix of integers and their dimensions as the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT