• C

Using an array

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?
yumaslimAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cwwkieCommented:
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.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
yumaslimAuthor 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.
0
cwwkieCommented:
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
0
deepu chandranCommented:
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.

0
PaulCaswellCommented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.