293 views

Consider the following program modifying an $n \times n$ square matrix $A$:

for i=1 to n:
for j=1 to n:
temp=A[i][j]+10
A[i][j]=A[j][i]
A[j][i]=temp-10
end for
end for

Which of the following statements about the contents of matrix $A$ at the end of this program must be TRUE?

1. the new $A$ is the transpose of the old $A$
2. all elements above the diagonal have their values increased by $10$ and all the values below have their values decreased by $10$
3. all elements above the diagonal have their values decreased by $10$ and all the values below have their values increased by $10$
4. the new matrix $A$ is symmetric, that is, $A[i][j]=A[j][i]$ for all $1 \leq i, j \leq n$
5. $A$ remains unchanged

edited | 293 views
0

In executing the code above, an element a[i][j] of Matrix is modified $2-times$, And thus final value of A remains unchanged.

1.for i=1 to n:
2.    for j=1 to n:
3.        temp=A[i][j]+10
4.        A[i][j]=A[j][i]
5.        A[j][i]=temp-10
6.    end for
7.end for

The $3,4,5$ lines swap $A [ j ] [ i ]$ and $A [ i ] [ j ]$.

The same variables are swapped twice. For eg when: $i =5$, $j = 10$. $A [10] [5]$ and $A [5] [10]$ will be swapped. They will be swapped again when $i = 10$, $j =5$.

Two times swap of same elements will lead to $A$ remaining unchanged.

Hence, E is correct.

by Active (1.7k points)
edited by
0

1
2