school has 100 lockers and 100 students. All lockers areclosed on the first day of school. As the students enter, the first student, denotedas S1, opens every locker. Then the second student, S2, begins with the secondlocker, denoted as L2, and closes every other locker. Student S3 begins with thethird locker and changes every third locker (closes it if it was open and opens it ifit was closed). Student S4 begins with locker L4 and changes every fourth locker.Student S5 starts with L5 and changes every fifth locker, and so on, until studentS100 changes L100.After all the students have passed through the building and changed the lockers,which lockers are open? Write a program to find your answer and display all openlocker numbers separated by exactly one space.
Control structures
Control structures are block of statements that analyze the value of variables and determine the flow of execution based on those values. When a program is running, the CPU executes the code line by line. After sometime, the program reaches the point where it has to make a decision on whether it has to go to another part of the code or repeat execution of certain part of the code. These results affect the flow of the program's code and these are called control structures.
Switch Statement
The switch statement is a key feature that is used by the programmers a lot in the world of programming and coding, as well as in information technology in general. The switch statement is a selection control mechanism that allows the variable value to change the order of the individual statements in the software execution via search.
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
as S1, opens every locker. Then the second student, S2, begins with the second
locker, denoted as L2, and closes every other locker. Student S3 begins with the
third locker and changes every third locker (closes it if it was open and opens it if
it was closed). Student S4 begins with locker L4 and changes every fourth locker.
Student S5 starts with L5 and changes every fifth locker, and so on, until student
S100 changes L100.
After all the students have passed through the building and changed the lockers,
which lockers are open? Write a
locker numbers separated by exactly one space.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps