Question: C programming Using loops, selection and input and output in C A custodial staff person at the College does a peculiar thing at night. There

C programming
C programming Using loops, selection and input and output in C A

Using loops, selection and input and output in C 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 will turn it on. Pressing it again will turn it off. The staff member walks down a corridor with n lights n times. On the ith trip he/she only toggles the switches whose position is divisible by i. When coming back to the initial position, he/she does not press any switches. Write a C 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 peculiar thing. Your program should prompt the user to enter a number and read the number. The program continues until the user enters 0. If the user enters a negative number, you should print an error message and prompt them to enter the number again. Your program should perform the necessary calculations to determine the state of the nth bulb and the result: The last bulb is (on/off). Possible sample output: Please enter a positive integer. Enter 0 to quit: -4 Error! This is not a positive integer. Please try again. Please enter a positive integer. Enter 0 to quit: 3 The last bulb is off. Please enter a positive integer. Enter 0 to quit: 4 The last bulb is on. Please enter a positive integer. Enter 0 to quit: 0 Have a nice day. Email me the.c file

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!