Generation

generate functionWed, 16 Nov 2022

# A high school has 100 students and 100 lockers.On the first day of school, the principal plays the following game: She asks the first student to go and open all the lockers. She then asks the second student to go and 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 fourth student is asked to check every fourth 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 turn, some of the lockers are open and some are closed. Your job is to tell how many lockers are open at the end of the game and if we take 100 students and 100 lockers the result should be 10. You have to implement this scenario using a function named “openLocks()”, which takes two input parameters i.e number_of_lockers and number_of_students that returns the number of lockers that are opened.

``````int openLocks(int number_of_lockers, int number_of_students){