PRASHNIKAप्रश्निका
‹ Back to the paper

Choose the correct option.

What is the method dimen() performing?

Computer Science20221 markMCQ
  • (i)Finding the product of the boundary elements
  • (ii)Finding the sum of the non-boundary elements
  • (iii)Finding the sum of the boundary elements
  • (iv)Finding the sum of the matrix elements
Show the code
void dimen(int n[][])
{
    int p = 0;
    for (int i = 0; i < n.length; i++)
        for(int j = 0; j < n[0].length; j++)
        {
            if(i == 0 || i == n.length - 1 || j == 0 || j == n[0].length - 1)
                p = p + n[i][j];
        }
    System.out.print(p);
}

Answer

Answer

AI

Correct option: (iii)

Answer: (iii) Finding the sum of the boundary elements The condition selects the first/last row and first/last column, and their values are added to p.
Arrays, Strings

From ISC 2022 Computer Science - Specimen paper (Semester 1), Paper 1, question 28(b).