



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Various aspects of loops in c++ programming, including the use of do-while, while, and for loops, loop control statements (break and continue), and examples of loop usage. It also discusses the differences between do-while and while loops.
Typology: Study notes
1 / 5
This page cannot be seen from the preview
Don't miss anything!




max is 5
number 0
sum is 14 count is 4
max is 5 number 0
while (number < 20) { number++; if (number != 10 && number != 11) sum += number; } cout << "The sum is " << sum; return 0; }
(a) Line 1: The semicolon (;) at the end of the for loop heading should be removed. Line 4: the semicolon (;) at the end of the if statement should be removed. Line 5: Missing a semicolon for the first println statement. Line 9: The semicolon (;) at the end of the while heading should be removed. Line 17: Missing a semicolon at the end of the do-while loop. (b) The loop will be executed only one time, because the test condition for the while clause is true.
Tip for tracing programs: Draw a table to see how variables change in the program. Consider (a) for example. i j output 1 0 0 1 1 2 0 0 2 1 1 2 2 3 0 0 3 1 1 3 2 2 3 3 4 0 0 4 1 1 4 2 2 4 3 3 4 4 (A). 0 0 1 0 1 2 0 1 2 3
1xxx2xxx4xxx8xxx16xxx 1xxx2xxx4xxx8xxx 1xxx2xxx4xxx 1xxx2xxx 1xxx (D). 1G 1G3G 1G3G5G 1G3G5G7G 1G3G5G7G9G
x is - The reason: When a variable is assigned a value that is too large (in size) to be stored, it causes overflow. 2147483647 + 1 is actually -
(A) n times (B) n times (C) n-5 times (D) The ceiling of (n-5)/3 times