UGC NET CS 2014 June-paper-2
October 10, 2023Programming
October 10, 2023Programming
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]); }
for(j = 0; j < 4; ++j){
t = M[i][j]; M[i][j] = M[j][i]; M[j][i] = t; } |
|
for(j = 0; j < 4; ++j){
M[i][j] = t; t = M[j][i]; M[j][i] = M[i][j]; } |
|
for(j = i; j < 4; ++j){
t = M[i][j]; M[i][j] = M[j][i]; M[j][i] = t; } |
|
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.
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.
In (D) , given statements is wrong as temporary variable needs to be assigned some value and not vice-versa.
Subscribe
Login
0 Comments