Answer to Question #299113 in C++ for Yaku

Question #299113

The following C++ program segment computes C = A * B, where A is an “m” by “n”

matrix, B is an “n” by “r” matrix and C is an “m” by “r” matrix.


for (long int i = 0; i < m; i++)

for (long int j = 0; j < r; j++)

{

long double Sum = 0;

for (long int k = 0; k < n; k++)

Sum = Sum + A[i][k] * B[k][j];

C[i][j] = Sum;

}



i) How many times does the code iterate in computing Sum?

ii) How many times does the code iterate in computing the j column of C, i.e. C[i][j] for a fixed i and j = 1, 2, 3, ..., r?

iii) How many times does the code iterate in computing the complete matrix C?


1
Expert's answer
2022-02-17T11:52:38-0500

i) To compute a single value of Sum the code make n iterations

ii) To compute j-th column of C the code produces r*n intertions

iii) There are m*r*n total iterations in the complete calculation of the matrix C.


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog