For each sample of code given below, indicate precisely how many times each line
ID: 3858985 • 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.
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; iExplanation / Answer
Q1 )
sum = 0 - 1 time
i=0 - 1 time
i<n - n times
i++ - n/3 times
sum = sum + array[i] - n/3 times
return sum - 1 times
Q2 )
sum = 0 - 1 time
i=1 - 1 time
i<n - n/3 times
i=i*3 - n/3 times
sum = sum + array[i] - n/3 times
return sum - 1 times
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.