Plz refer below img.
Q.B:->Error is there bcz we are swapping content of cells of matrix two times whose overall effect is Nothing .
Correction is only J=I+1 instead of J=1 .
By doing above change in code we are swapping only Upper triangular part with Lower triangular which is nothing but Transpose of matrix.
Everything else is All is Well ;)