So I have a program scenario for a postman who carries out an experiment:
1. He has mailboxes numbered 1-150 all of which are 'closed'
2. Starting with mailbox 2, he 'opens' all even-numbered mailboxes, leaving all others 'closed'
3. Next, beginning with mailbox 3,goes on to 'open' every third 'if' its 'closed' and 'if' its 'open' he 'closes' it
4. He repeats step (3) with the 4th,5th...nth mailbox, opening or closing every 4th, 5th...nth mailbox accordingly.
5. display open and closed mailboxes

i need some codes for this problems. i cant finish it because it so difficult. someone there want to help me?

This is a neat problem - if you think about it, you might be able to work out the final state of the "experiment", but it does take a bit of an "aha!" moment.

While you're mulling that over, the best way to start writing a program like this is to walk through the steps in pencil and paper. Draw fifteen boxes (easier than 150!) and mark them as "open" or "closed" as you go through the steps. This should help you get clear on what you need to do.

Then, you might want to think about what data you need to work with in the program, and how to represent it.

As Ezzaral says, work at it a while and come back with some real questions, and you'll probably get some good answers.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.