Hi! Everyone i'm mark a student taking (I.T). I was given an assignment to create a matrix that is 3 by 3 without explaining how to do it, but instead of complaining i browsed the internet and try to find some sample codes on how to create a simple 3 by 3 matrix.
My instructor gave me this output:
The transpose of a matrix:
(1st)
12 13 14
15 16 17
18 19 11
(2nd)
12 15 18
13 16 17
14 19 11
(3rd)
12 15 18
13 16 19
14 17 11
The interchanging of the rows with the corresponding columns.
I don't know how to create the for loop to interchange the numbers,
can anyone help me? I need a sample code to refer to.
I would be thankful if anyone can give me any sample codes. :)
I'm using Turbo C, C++, I don't know how to use any other programming language.
Thank you in advance for anyone's help.
If matrix T is a transpose of matrix M, T[i][j] == M[j][i].
First have a for loop for each row, then, inside it, a for loop for each column. Lastly do the assignment with swapped indices (like above).
This could be done without making a copy, but then the for loops would have to be a bit more complicated.
Janlan: Thank you for giving me a sample code, its a great help. ^^
I'm kinda new to the cout<<" "<<(array); cout<<endl; function.
Can you tell what its for?
Iv'e seen it in many programs when i searched for this matrix
sample code in webs but still i need further explanation
to understand the full use of it.
Thanks again for the sample code, the for loops a bit confusing :D LOL but i'm getting it now.
I just need to understand the cout function and its all done :)
If you just want to print the transpose, change matrix[i][j] to matrix[j][i]. If you want to save the transpose in another array, in the same for loop write transpose[i][j] = matrix[j][i].