Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For each sample of code given below, indicate precisely how many times each line

ID: 3857819 • Letter: F

Question

For each sample of code given below, indicate precisely how many times each line runs in terms of the variables given. Sometimes, you will be able to give an exact integral answer, like "10". Other times, your answer will be in terms of n or some other variable or combination of variables. If the snippet of code is a method, you do not have to write the number of times the top line (the method declaration itself) is executed.

Question:

//matrix multiplication of A[m][n] and B[n][p]. The product is saved into C[m][p].

void mult_matricies( double A[][n], double B[][p], double C[][p], int m, int n , int p ){

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

for (int j=0; j<p; j++){

C[i][j] = 0;

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

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

}//for-k

}//for-j

}//for-i

}

Explanation / Answer

Hi,

Please see below the answer. Please comment for any queries/feedbacks.

Thanks!

//matrix multiplication of A[m][n] and B[n][p]. The product is saved into C[m][p].

void mult_matricies( double A[][n], double B[][p], double C[][p], int m, int n , int p ){

for (int i=0; i<m; i++) { //outer loop will run m times

for (int j=0; j<p; j++){   //inner loop will run m X p times

C[i][j] = 0;

for ( int k=0; k<n; k++) {   //inner loop will run m X p X n times

C[i][j] += A[i][k] * B[k][j];   //inner loop statement will run m X p X n times

}//for-k

}//for-j

}//for-i

}