Peter the postman became bored one night and, to break the monotony of the night shift, he carried out the following experiment with a row of mailboxes in the post office. These mailboxes were numbered 1 through 150, and beginning with mailbox 2, he opened the doors of all the even-numbered mailboxes, leaving the others closed. Next, beginning with mailbox 3, he went to every third mail box, opening its door if it were closed, and closing it if it were open. Then he repeated this procedure with every fourth mailbox, then every fifth mailbox, and so on. When he finished, he was surprised at the distribution of closed mailboxes. Write a program to determine which mailboxes these were.


First write a function to initialize all mailbox doors to closed (you can use Boolean type for closed or not).

Next write a second function that will conduct what Peter did as described above.

Next write another function that will output all of the mailboxes whose doors are closed.

Next write the main function. In your main function, call all of the above three functions to find out the distribution of closed mailboxes for Peter.

Source link

Leave a Reply

Your email address will not be published. Required fields are marked *