Lab 3: Arrays

The goal of this lab is to practice creating and using basic arrays. This reading gives you a chance to think about the problem before you come to class. Note that you do need to indicate (at the bottom of this page) that you have done the reading.

A. Problem statement

Once there was school hallway with 1000 lockers, numbered 1 to 1000. Initially, all the lockers were open. Then someone came along and closed every other locker—the second, the fourth, the sixth, etc. Next, someone came along and and switched (closed it if it was open, opened it if it was closed) every third locker—closed the third, opened the sixth, closed the ninth. After that, someone did the same for every fourth locker—opened the fourth, opened the eighth, closed the twelfth. Many such people came along, the last one switching the 50th locker, the 100th locker, the 150th locker, etc.

At the end of all this locker-opening and closing, how many lockers were open and how many were closed? Which locker got switched the most often? You will write a program to answer these questions.

I, read the pre-lab

Thomas VanDrunen and Cary Gray
Last modified: Thu Sep 19 16:54:06 CDT 2013