const int n = 4;
int matrix[n][n];
//initialize matrix...
Trying to work out transpose of n sized matrix
Hi, I don't know what is wrong with me, but I can't work out how to get the transpose of a n sized matrix.
I can do it fine manually, but I can't wrap my head around it. So if I had the code:
can someone tell me an algorithm to transpose this matrix?
Thanks
Just remember that m[j] and m[j] are swapped, and diagonal elements are unchanged. There are various ways to implement the function, depending I suppose on how concerned you are with efficiency. Here's one way you could do it (no guarantee of correctness):
for (int j = 1; j < size; ++j) { for (int i = 0; i < j; ++i) { float temp = m[j]; m[j] = m[j]; m[j] = temp; }}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement