Arrays & Strings
![Question 10, GATE 2014: For an n×n matrix A, execute C=100; for i=1,…,n and j=1,…,n execute Temp=A[i][j]+C; A[i][j]=A[j][i]; A[j][i]=Temp−C. Then print A in row order. What is printed? A original A; B transpose of A; C upper-diagonal entries increased by 100 and lower-diagonal entries decreased by 100; D none of these.](../../assets/questions/CS-2014-S3-Q20-1.webp)
Your answer
Answer & solution
Official answer: A
Step 1: Track one iteration with old values u=A[i][j] and v=A[j][i]. Temp=u+100, then the assignments store v and (u+100)−100=u, so the body swaps the two entries. Step 2: For i≠j, both index pairs (i,j) and (j,i) occur in the complete nested loops. The second swap undoes the first. A diagonal entry is swapped with itself. Step 3: Consequently every entry finishes unchanged, A. This reasoning uses exact arithmetic or assumes no problematic overflow in adding and subtracting C.