Control Loops: A high school 1000 students and 1000 lockers. The principal plays the following game: She asks dthe first student to open all the lockers. Shen then asks the second student to close all the even-numbered lockers. The third student is asked to check every third locker. If it is open, the student closes it; if it is closed, the student opens it. The remaining students continue this game . In general, the nth student  checks every nth locker. If the locker is open, the student closes it; if it is closed, the student opens it. After all the students have taken their turns, some of the lockers are open and some are closed. Write a program thatprompts the user to enter the number of lockers in a school. After the game is over, the program outputs the number of lockers  and the locker numbers of the lockers that are open. Test run your program for the following inputs: 1000, 5000, 10,000. Do you see any pattern developing for the locker numbers that are open in the output? (Hint: Consider locker number 100. This locker is visied by student numbers 1, 2, 4, 5, 10, 20, 25, 50, and 100. These are the postive divisors of 100. Similarly, locker number 30 is visited by student numbers 1, 2, 3, 5, 6, 10, 15, and 30. Note that if the number of positive divisors of a locker is odd, then at the end of the game the locker is open. If the number of positive divisors of a locker number is even, then at the end of the game the locker is closed.) I don't any code because I don't have a clue on where to begin. Thank you

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter4: Selection Structures
Section: Chapter Questions
Problem 14PP
icon
Related questions
icon
Concept explainers
Question
100%

Control Loops:

A high school 1000 students and 1000 lockers. The principal plays the following game: She asks dthe first student to open all the lockers. Shen then asks the second student to close all the even-numbered lockers. The third student is asked to check every third locker. If it is open, the student closes it; if it is closed, the student opens it. The remaining students continue this game . In general, the nth student  checks every nth locker. If the locker is open, the student closes it; if it is closed, the student opens it. After all the students have taken their turns, some of the lockers are open and some are closed. Write a program thatprompts the user to enter the number of lockers in a school. After the game is over, the program outputs the number of lockers  and the locker numbers of the lockers that are open. Test run your program for the following inputs: 1000, 5000, 10,000. Do you see any pattern developing for the locker numbers that are open in the output?

(Hint: Consider locker number 100. This locker is visied by student numbers 1, 2, 4, 5, 10, 20, 25, 50, and 100. These are the postive divisors of 100. Similarly, locker number 30 is visited by student numbers 1, 2, 3, 5, 6, 10, 15, and 30. Note that if the number of positive divisors of a locker is odd, then at the end of the game the locker is open. If the number of positive divisors of a locker number is even, then at the end of the game the locker is closed.) I don't any code because I don't have a clue on where to begin. Thank you

Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Control Structure
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT