Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I HAVE ANSWERS to these problems........I need good explanations!!!!!!!!! During

ID: 3552668 • Letter: I

Question

I HAVE ANSWERS to these problems........I need good explanations!!!!!!!!!



During execution of the following program segment:

a. How many times does the first call to printf execute?

b. How many times does the second call to printf execute?

c. What is the last value displayed?

for (i = 0; i < 7; ++i) {

for (j = 0; j < i; ++j)

printf("%4d", i * j);

printf(" ");

}








What are the values of x, y, and zafter execution of this three-statement

fragment?

x =3 y =5 z =2


x *= y + z;

y /= 2 * z + 1;

z += x;

Explanation / Answer

for (i = 0; i < 7; ++i) {

for (j = 0; j < i; ++j)

printf("%4d", i * j);

printf(" ");

}


a. How many times does the first call to printf execute?

Ans = 21 times

Because it is in inner loop which runs i times at each iteration, and the total number of iterations are 7 0 to 6 therefore

for i=0 it runs 0 times, for i=1 1 time........for i=6 times

so Total = 0+1+2+3+4+5+6 = 21 times


b. How many times does the second call to printf execute?

Ans = 7 times

Because it is in the outer loop and outer loop iterates for 7 times 0 to 6 therefore

second printf is called 7 times

c. last value will be

Ans = outer loop runs till i=6 and inner loop runs till j=5 therefore last output = i*j = 6*5 = 30


What are the values of x, y, and zafter execution of this three-statement

fragment?

x =3 y =5 z =2


x *= y + z;

y /= 2 * z + 1;

z += x;


only the first statement will make changes in x

so x=x*[y+z]

x=3*7

x=21

y=5/5 = 1

x is now 21

z=z+x

z=21+2 =23