C++ Practice Question.

Nov 16, 2011 02:37

A high school has 1000 students and 1000 lockers, one locker for each student. 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 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 it 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.

Write a program that prompts the user to enter the number of lockers in a school. After the game is over, the program outputs the number of lockers that are open.

SERIOUSLY WHY DOES THIS SOUND LIKE A LAYTON PUZZLE XD

And, they even give hints just like in the game. I can see it being played out. lol

But my head's fuzzed after trying to tackle the next question, about economics. I really feel like collapsing now, funny cos I can usually work this long (around 7 hours) without getting this dizzy... I'm also working on the laptop on my bed, but too lazy to move it off before I go to sleep so I woke up with a sore back yesterday morning, curled up on the 3/4 space of the single bed I have left...

I really need to get enough sleep in a proper position. Good night...

rants

Previous post Next post
Up