For each sample of code given below, indicate precisely how many times each line
ID: 3687323 • 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.
You are welcome to submit your responses as text files or scanned images.
5. (Extra credit - 10 pts) for (int i-0 i-; j--) 26. (10 pts) double sum matrix(double matrix[, int m, int n) i //m: num of rows: n: num of cols double sum=0; for (int i-n-1; i>=0; i--) for ( int jan-1; j>=0; j-) { sum = sum + matrix[ U sum = sum + ma t ril i ] [ j ]; return sum;Explanation / Answer
5) for(int i=0;i<n;i++) // this statement executes for n times
for(j=n/2;j>i;j--) // this statement exectues for n/2-i times
sum=i+j; // this statement executes for n/2! times;
6)
double sum=0; // for each call one time
for(int i=m-1;i>=0;i++) // this statement executes for m times
for(int j=n-1;j>=0;j++) // this statement executes for n times
sum=sum+matrix[i][j]; // this statement executes for m*n times
return sum; // for one time
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.