Question: Here are three fragments of code. Assume that integer variables have been declared already, and that sum is initialized somewhere to zero. /* loop 1

Here are three fragments of code. Assume that integer variables have been declared already, and that sum is initialized somewhere to zero.

/* loop 1 */

for( j = 1; j < 20; j *= 2 )

sum += j;

/* loop 2 */

for( j = 16; j; j /= 2 )

sum = sum + j;

/* loop 3 */

j = 1;

while ( j < 16 )

{

sum += j;

j *= 2;

}

The loops 1, 2, and 3 set sum to:

15, 15, 31
31, 31, 15
32, 32, 32
31, 31, 31
32, 32, 16

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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!