Question
The Locker Puzzle: Using C++ A school has 100 lockers and 100 students. All lockers are closed on the first day of school. As the
The Locker Puzzle: Using C++
A school has 100 lockers and 100 students. All lockers are closed on the first day of school. As the students enter, the first student, denoted S1, opens every locker. Then the second student, S2, begins with the second locker (L2) and closes every other locker. Student S3 begins with L3 and changes every third locker, opening it if it is closed, or closing it if it is open. Student S4 begins with L4 and changes every fourth locker. Student S5 begins with L5 and changes every fifth locker, etc. Student S100 only touches locker L100 and changes it.
Display a list of open lockers, with each locker number separated by a space.
Hint: use an array of 100 bool elements, each indicating if the locker is open (true) or closed (false). Remember, initially all lockers are closed (false).
Note: solutions that do not use loops and arrays to compute which lockers are open will be graded with a zero. The point of this exercise is to have you work with loops and arrays and to have the computer do the work of calculating the solution.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started