GateAI
Programming in C

GATE CSE 2014 Set 3 · Q10

MCQ1 markEasy

Time

Let A be a square matrix of size n×nn \times 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]);

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: A) The matrix A itself

Programming in C

In the nested loop:

  1. For each pair (i,j)(i, j):

    • Temp = A[i][j] + 100

    • A[i][j] = A[j][i]

    • A[j][i] = Temp - 100 = A[i][j]

This swaps the elements A[i][j] and A[j][i].

  1. The nested loops run for all ii from 11 to nn and all jj from 11 to nn:

    • For any off-diagonal pair where $i

e j,theswapoperationisexecutedtwice:oncewhen, the swap operation is executed twice: once when (i, j)isvisited,andasecondtimewhen is visited, and a second time when (j, i)isvisited.−Swappingthetwoelementstwicerestoresthemtotheiroriginalvalues.−Fordiagonalelementswhere is visited. - Swapping the two elements twice restores them to their original values. - For diagonal elements where i = j$, swapping an element with itself leaves it unchanged.

Hence, the matrix remains unchanged, and the output is the matrix A itself (Option A).

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Programming in C previous year question is Q10 of the GATE CSE 2014 Set 3 paper. Find more GATE CSE PYQs on Programming in C in Programming and Data Structures, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Programming in C PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Programming in C in GATE CSE

Programming in C has 74 GATE CSE PYQs across 25 papers from 2011 to 2026. 20 of them are 1-mark MCQs like this one, and GATE CSE 2014 Set 3 has 3.

How GATE tests Programming in C

More from GATE CSE 2014 Set 3

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2014 Set 3 · Q10 · MCQ

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]);

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.