subject

A custodial staff person at the College does a peculiar thing at night. There is a corridor with a number of lights controlled by toggle switches. Initially all lights are off. Pressing the switch on a light will turn it on. Pressing it again will turn it off. This staff member walks down a corridor with n light n times. On the ith trip the person only toggles the switches whose position number is divisible by i. When coming back to the initial position, the person does not press any switches. Write a program that determines the state (on or off) of the last light in the corridor after the staff member has made n trips up and down the corridor doing this routine Your program should prompt the user for the number of lights in the corridor, read the number and determine and print the value of the last light. You should print an error message if the user does not enter a positive integer. Use a loop for multiple inputs. The loop should terminate when the user enters 0 for the number of lights. Possible sample output: Please enter a positive integer. -3 This is not a positive integer. Please try again. Please enter a positive integer. 3 The last bulb is off. Please enter a positive integer. 0 Have a nice day.

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 20:30
1. for which of the following are you not required to signal beforehand? a. changing lanes b. speeding up c. stopping
Answers: 2
question
Computers and Technology, 23.06.2019 22:40
22. sata3 allows for data transfer rates of 600 mb/s. explain why you would likely not be able to copy data from one hard drive to another at anywhere close to this speed. also, what could be upgraded on the computer to achieve transfer speeds closer to 600 mb/s
Answers: 1
question
Computers and Technology, 24.06.2019 13:20
In the insert table dialog box, you select the checkbox to create the first row as the header of the table.
Answers: 3
question
Computers and Technology, 24.06.2019 14:00
Which computer tools allow you to communicate with coworkers, family,and friends
Answers: 1
You know the right answer?
A custodial staff person at the College does a peculiar thing at night. There is a corridor with a n...
Questions
question
Chemistry, 22.08.2020 18:01
Questions on the website: 13722363