Hi i´m writing a program that takes user inputs into a 2d array. The user decides number of row and columns and inputs the numbers in the array. The program needs to print out the array and print out a mirrored version. This is what I have came up with but I need help with the mirrored array.
By "mirrored" do you mean the usual mathematical matrix term "transposed" (i.e. swap rows and columns)?
If so then:
(i) mirrow would actually have to have col "rows" and row "cols" (e.g. a 2x5 matrix would become 5x2 when transposed). At the moment this isn't what you have.
(ii) mirror[i][j] = array[j][i], with i cycling through the "rows" of mirror and similarly j cycling through the "cols" of mirror.
If I have the wrong end of the stick then please clarify "mirrored".
Couple of minor issues:
(iii) Might be a good idea to prompt the user for his input, rather than assuming knowledge of the order of inputs.
(iv) I'm never quite sure about declaring the size of arrays (here, row and col) at RUN-time; it always seems to work, but I sort of feel one ought to be dynamically allocating them.
If you want to "mirror" (i.e. reverse) in BOTH horizontal and vertical directions for a 2d array then the last pair of nested loops could be written as follows, with ii and jj declared as integers at the start of your program. (Note that I'm still wondering if "transposed" might have been what was really intended.)
Sorry - missed your previous reply. However, if you want to get the LEFT-RIGHT mirrored version then you can just change the ii= line in my suggestion to ii = i;
(so allowing you some variants later, if, as I still suspect, this wasn't what was intended by the question; it's quite an unusual matrix operation to be asked to do.)
I´m not supposed to transpose the matrix just reflect the matrix as I explained in previous comment. when I run the code I have like I put in the first comment I get :