Answer the question
In order to leave comments, you need to log in
How to swap columns in a matrix?
How to swap columns in a matrix? There is a 5x5 matrix. You need to swap the first and second columns. In what ways can this be implemented?
Answer the question
In order to leave comments, you need to log in
If you use rectangular arrays - then only in a loop.
If you are using jagged arrays, then the data in the matrix must be in column-major order so that two columns can be jagged. But usually we use row-major in programming (so that the first index is on the X axis, so to speak), so if you have it, then, again, only cycles will help.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question