Question: IN C++ For each sample of code given below, indicate precisely how many times each line runs in terms of the variables given. Sometimes, you

IN C++

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.

Q1.

double sum_triples(double array[], int n) {//n: size of the array. Assume n is divisible by 3

double sum=0;

for (int i=0; i

sum = sum + array[ i ];

return sum;

}

Q2.

double sum_exponentials(int n){ //n is a power of 3, i.e., n=3^k or k=log n base 3

int sum=0;

for (int i=1; i

sum = sum + i;

return sum;

}

Q3.

for (int i=0; i

for (int j=n; j>=i; j--)

cout << i << , << j <

}

Q4.

for (int i=0; i n = 2*k

for (j=n/2; j>i; j--)

sum = i+j;

}

Q5.

//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

for (int j=0; j

C[i][j] = 0;

for ( int k=0; k

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

}//for-k

}//for-j

}//for-i

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The question is incomplete because the loop conditions are ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!