UGC NET CS 2014 June-paper-2
October 10, 2023
Programming
October 10, 2023
UGC NET CS 2014 June-paper-2
October 10, 2023
Programming
October 10, 2023

Programming

Question 3

Consider the following C program which is supposed to compute the transpose of a given 4 x 4 matrix M. Note that, there is an X in the program which indicates some missing statements. Choose the correct option to replace X in the program.

#include<stdio.h>
#define ROW 4
#define COL 4
int M[ROW][COL] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
main()
{
    int i, j, t;
    for (i = 0; i < 4; ++i)
    {
        X
    }
    for (1 = 0; i < 4; ++i)
        for (j = 0; j < 4; ++j)
            printf ("%d", M[i][j]);
}
A
for(j = 0; j < 4; ++j){
t = M[i][j];
M[i][j] = M[j][i];
M[j][i] = t;
}
B
for(j = 0; j < 4; ++j){
M[i][j] = t;
t = M[j][i];
M[j][i] = M[i][j];
}
C
for(j = i; j < 4; ++j){
t = M[i][j];
M[i][j] = M[j][i];
M[j][i] = t;
}
D
for(j = i; j < 4; ++j){
M[i][j] = t;
t = M[j][i];
M[j][i] = M[i][j];
}
Question 3 Explanation: 
To compute transpose ‘j’ needs to be started with ‘i’. So, A and B are wrong.
In (D) , given statements is wrong as temporary variable needs to be assigned some value and not vice-versa.
Correct Answer: C
Question 3 Explanation: 
To compute transpose ‘j’ needs to be started with ‘i’. So, A and B are wrong.
In (D) , given statements is wrong as temporary variable needs to be assigned some value and not vice-versa.
0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
error: Alert: Content selection is disabled!!