Note that for transposed matrix matT of matrix mat the following relation holds:
Wrap this thing in two nested loops and you're in business.
kind regards,
Jos
Do that and you are out of business.
1. you will lose elements as you are not swapping them just replacing and by the time you get to the other elements you are lost. So replace this simple statement be three statements , that first saves the target elements before swapping.
2. Now even if you fixed that in step 1. You are lost because, you will be first swapping and then re-swapping. the two nested loops are not enf, you have to check you swap only one side and other side is done