We help IT Professionals succeed at work.

Using an array

on
Medium Priority
222 Views
I want to use an array that will tell me which doors are open at the end of an experiment.  The experiment involves 100 students (who are numbered 1 through 100) and 100 doors (also numbered 1 through 100).  All doors begin as closed, but become open when a student goes through.  The students go through all doors that are multiples of their given number.
My first step would be to set up an array of 100 integers, but then how do I change their values of the array in multiples of the student's numbers?
Comment
Watch Question

View Solutions Only

Commented:
If your platform supports a boolean type, it is better to use that, but an array of 100 integers if fine. Let's say 0 means the door is closed, and 1 means the door is open.

You first need to set all doors to closed

Then you loop through all students, and you let each student open the doors based on their number.

At the end you check which doors are still closed.

Just try to start with this, and post the code when you're stuck.

Not the solution you were looking for? Getting a personalized solution is easy.

Commented:
How would I change the values of the doors based upon the student's number?  That's really where I'm getting stuck right now.

Commented:
Maybe use an enum for the doors;

typedef enum {DoorClose, DoorOpen} DoorState;
DoorState Doors[100];

To close a door, you do
Doors[0]=DoorClose;
to open a door:
Doors[0]=DoorOpen;

But post the code you have so far, so we can take a look at it.
Take a look here for some hints to get started http:Q_21676313.html

Commented:
hi friend,
you can solve this through parallal array concept.i think u are expecting a logic like that

you can this using the following arrays,

DoorState Doors[100];
DoorStatus DS[100];

you can use cwwkie's logic along with this.

Commented:
Hi yumaslim,

Say a student has number 2. You must therefore set doors 2, 4, 6, ... to open. Use a loop starting at 2 and stepping by 2 each time until you reach 100.

Sorry we cant actually give you the code as this is a homework question.

Paul
Thanks for using Experts Exchange.

• View three pieces of content (articles, solutions, posts, and videos)
• Ask the experts questions (counted toward content limit)
• Customize your dashboard and profile