OpenStudy (anonymous):

I've seen this question on the site, but do not understand how the answer was attained: For the algorithm below, compute the number of multiplications performed, as well as the final value of s. p ← 1 s ← 0 for i is in {1, 2, 3, 4} do p ← p · 3 s ← s + p number of multiplications final value of s s =

3 years ago
OpenStudy (anonymous):

I'm not quite sure about the "for i is in {1,2,3,4} do". If it is anything like C, ie: for( int i =0; i < 4; i++ ) { p = p * 3; s = s + p; } Then the loop will be executed four times, and each statement in this case will execute once for each loop. Try using a table to keep track of the values in the variables in order to determine what the value of s is at the end of execution. As for the number of multiplications, I think from my previous paragraph you can now figure that out.

3 years ago
Similar Questions: