Using an array

Posted on 2006-03-25
Last Modified: 2010-04-15
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?
Question by:yumaslim
    LVL 14

    Accepted Solution

    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.

    Author Comment

    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.
    LVL 14

    Expert Comment

    Maybe use an enum for the doors;

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

    To close a door, you do
    to open a door:

    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
    LVL 8

    Expert Comment

    by:deepu chandran
    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.

    LVL 16

    Assisted Solution

    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.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
    Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode ( They will have you believe that Unicode requires you to use…
    The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
    The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now