GATE CS 2014, set 3 · Question 20 · Programming and Data Structures · Multiple choice (MCQ) · 1 mark · −1/3 for a wrong answer

Let A be a square matrix of size n × n. Consider the following pseudocode. What is the expected output?
C = 100; for i = 1 to n do for j = 1 to n do { Temp = A[i][j] + C; A[i][j]= A[j][i]; A[j][i] = Temp - C; } for i = 1 to n do for j = 1 to n do output (A[i][j]);

  1. (A) The matrix A itself
  2. (B) Transpose of the matrix A
  3. (C) Adding 100 to the upper diagonal elements and subtracting 100 from lower diagonal elements of A
  4. (D) None of the above
Answer

Answer (A)

Answer from the official GATE CS 2014 answer key.

The step-by-step solution, where available, is part of GATE CS Pro. See what Pro includes