Home » Programming & Data Structure » Programming and data structure miscellaneous » Question

Programming and data structure miscellaneous

Programming & Data Structure

  1. 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. The matrix A itself
    2. Transpose of the matrix A
    3. Adding 100 to the upper diagonal elements and subtracting 100 from lower diagonal elements of A
    4. None of the above
Correct Option: A

For the given pseudo code, each element of the upper triangle is interchanged by the corresponding element in lower triangle and later the lower triangular element is interchanged by the upper triangular once. Thus the final output matrix will be same as that of input matrix A.



Your comments will be displayed only after manual approval.