Ok so basically for such Questions just need to see operation and then loop
Observe :-
Temp = A[ i ] [ j ] + C ;
A [ i ] [ j ] = A [ j ] [ i ] ;
A [ j ] [ i ] = Temp - C ;
This is nothing but standard transpose operation
which can also be remembered as :
Temp = A[ i ] [ j ] ;
A [ i ] [ j ] = A [ j ] [ i ] ;
A [ j ] [ i ] = Temp ;
Now next thing to do is to observe the loops carefully,
There are basically 3 Rules or 3 similar type loops
other than this it is mostly unlikely to be asked in exam
Rule 1 :-
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
swap(A[i][j], A[j][i]);
Every pair is visited twice
Output = Original Matrix
Rule 2 :-
for(i=1;i<=n;i++)
for(j=i+1;j<=n;j++)
swap(A[i][j], A[j][i]);
Only upper triangular part is visited.Each pair is swapped exactly once.
Output :- Transpose
Rule 3 :-
for(i=1;i<=n;i++)
for(j=1;j<i;j++)
swap(A[i][j], A[j][i]);
Only lower triangular part is visited.
Again, each pair is swapped exactly once.
Output :- Transpose
That's it And all set!