# Quiz 2 Loops

Content type
User Generated
Subject
Programming
School
CUNY Borough of Manhattan Community College
Type
Homework
Rating
Showing Page:
1/4
The College of Staten Island
Department of Computer Science
Fall 2020 CSC 126
Mrs. S. Nevins
Quiz #2: Chapter 5 (a.k.a Loop-palooza)
Name:
Okikijesu Ogunyemi
Part 1 Multiple Choice (3 Points, 1 Point Each). Place the letter of the correct answer on the line
to the LEFT of the question number.
__c___1. Which of the following loops is guaranteed to execute at least once?
a. counter controlled while loop c. do…while loop
b. for loop d. sentinel-controlled while loop
__d___2. What is the value of x after the following statements execute?
int x = 5, y = 30;
do
x = x * 2;
while (x < y);
a. 5 c. 20
b. 10 d. 40
__c___3. A loop that continues to execute endlessly is called a(n) _______________ loop.
a. end c. infinite
b. unhinged d. definite
=============================================================================
=======
Part 2 Code Segments
a. (3 Points) Write a code segment (not a whole program) that prints out the numbers from 100 to 50
(inclusive) that are multiples of 5 backwards (i.e. 100, 95, 90, 85, 80, etc.).
int i;
for (i = 100; i >= 50; i++)
{
cout << i << endl;
}

Showing Page:
2/4
b. (4 Points) A triangular number is the sum of the n natural numbers from 1 to n.
For example:
The triangular number for 3 is 1 + 2 + 3 = 6
The triangular number for 7 is 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28
Write a program segment (using a loop), that calculates and then prints the integer n and its
triangular number.
int i;
int sum = 0;
for (i = 1; i <= n; i++)
{
sum += i;
}
cout << sum;
---------------------------------------------------------------------------------------------------------------------------------------
------------
c. (4 Points) Given the following program segment….
for (num = 10; num >= 1; num--)
cout << setw(3) << num;
Write a while loop that will have the same output.
int num = 10;
while (num >= 1)
{
cout << setw(3) << num;
num--;
}

Showing Page:
3/4

End of Preview - Want to read all 4 pages?
Access Now
Unformatted Attachment Preview
The College of Staten Island Department of Computer Science Fall 2020 – CSC 126 Mrs. S. Nevins Quiz #2: Chapter 5 (a.k.a Loop-palooza) Name: Okikijesu Ogunyemi Part 1 – Multiple Choice (3 Points, 1 Point Each). Place the letter of the correct answer on the line to the LEFT of the question number. __c___1. Which of the following loops is guaranteed to execute at least once? a. counter controlled while loop c. do…while loop b. for loop d. sentinel-controlled while loop __d___2. What is the value of x after the following statements execute? int x = 5, y = 30; do x = x * 2; while (x < y); a. 5 b. 10 c. 20 d. 40 __c___3. A loop that continues to execute endlessly is called a(n) _______________ loop. a. end c. infinite b. unhinged d. definite ============================================================================= ======= Part 2 – Code Segments a. (3 Points) Write a code segment (not a whole program) that prints out the numbers from 100 to 50 (inclusive) that are multiples of 5 backwards (i.e. 100, 95, 90, 85, 80, etc.). int i; for (i = 100; i >= 50; i++) { cout ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

### Review

Anonymous
Great content here. Definitely a returning customer.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4