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

8. Which of the loop statements is ideal for situations that require a counter a

ID: 3622652 • Letter: 8

Question

8. Which of the loop statements is ideal for situations that require a counter

a. The do-while loop
b. The for loop
c. Nested loops
d. The while loop


9. Convert the following while loop to a for loop

a = 8; sum=0;
while ( a > 0 ) { sum = sum + a; a= a - 1; }



a. for (a=8; sum=0 ; a > 0; a--) sum ++;
b. for (a=8, sum =0 ; a > 0; a--) sum += a;
c. for (a=8; sum=0 ; a > 0; a=a-1) sum + a;
d. for (a=8, sum =0 ; a < 0; a--) sum += a;


10. How many times will the value in the variable tmp be displayed in the following program segment? (assume output displays the value of the variable).

int x, y, z; int tmp=0;
for (x=0; x<2; x++)
for (y=0; y<2; y++)
for (z=0; z<2; z++) output (tmp);

a. 0
b. 2
c. 6
d. 8

Explanation / Answer

answers:

8 d) The while loop          it require counter.

9) b. for (a=8, sum =0 ; a > 0; a--) sum += a;

10) d. 8 times tmp will be printed.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote