Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essential SQLAlchemy Mapping Python To Databases

Authors: Myers, Jason Myers

2nd Edition

1491916567, 9781491916568

More Books

Students also viewed these Databases questions