adplus-dvertising
frame-decoration

Question

Select the code snippet which performs matrix multiplication.(a and b are the two given matrices, resultant marix is c)
a)

for (int i = 0; i < n; i++)
{
    for (int j = 0; j < n; j++)
    {
        for (int k = 0; k < n; k++)
        {
            c[i][j] = c[i][j] + a[i][k] * b[k][j];
        }
    }
}

b)

for (int i = 0; i < n; i++)
{
    for (int j = 0; j < n; j++)
    {
        for (int k = 0; k < n; k++)
        {
            c[i][j] = c[i][j] * a[i][k] * b[k][j];
        }
    }
}

c)

for (int i = 0; i < n; i++)
{
    for (int j = 0; j < n; j++)
    {
        for (int k = 0; k < n; k++) 
        {
            c[i][j] = c[i][j] + a[i][k] + b[k][j];
        }
    }
}

d) None of the mentioned

a.

a

b.

b

c.

c

d.

d

Answer: (a).a

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. Select the code snippet which performs matrix multiplication.(a and b are the two given matrices, resultant marix is c)