Like Tree2Likes
  • 2 Post By ZuK

100 doors 100 students help

This is a discussion on 100 doors 100 students help within the C Programming forums, part of the General Programming Boards category; I'm trying to make a simple code for this problem: There are 100 doors (numbered 1 through 100) and 100 ...

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    6

    100 doors 100 students help

    I'm trying to make a simple code for this problem: There are 100 doors (numbered 1 through 100) and 100 students (numbered 1 through 100) waiting in a line. Initially, all the doors are open. A student numbered x passes through all the doors that are multiples of x (i.e., student numbered x goes to doors x; 2x; 3x; ... ) and changes the status of each door, i.e., opens the door if it is closed and closes the door if it is open. After all the students complete their turns, which doors remain open?

    anyway here is my code for it:

    Code:
    #include<stdio.h>
    
    
    int main(void) {
        int door = 1;
        int student = 1;
        int check;
        int counter = 0;
        int open = 0;
        int check2;
        
        for (door ; door <= 100 ; door++) 
        {
    
    
            for (student = 1;  student <= door ; student++)
            {
                check = (door % student);
                if (check = 0)
                {
                    counter = counter + 1;
                    printf("321");
                }
            }
            check2 = counter % 2;
            if (check2 = 0)
            {
                open = open + 1;
                printf("123");
            }
        }
        printf(" %d ", open);
    }
    the code never seems to enter the if statements which is clearly a problem. I just don't know what went wrong with this. Any help would be very appreciated/

  2. #2
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Code:
    if (check = 0) this is assignment
    you want
    Code:
    if (check == 0)
    Also you need to have an array of 100 doors to store the status of the door

    Kurt

  3. #3
    Registered User
    Join Date
    Feb 2013
    Posts
    6
    I knew it had to be something silly like that. Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. opening doors game
    By green_ghoul in forum C Programming
    Replies: 6
    Last Post: 11-09-2011, 05:02 PM
  2. need help with sorting students GPA
    By cprogisfun in forum C Programming
    Replies: 7
    Last Post: 12-10-2010, 06:14 AM
  3. Doors in a raycasting engine
    By lmaster in forum Game Programming
    Replies: 3
    Last Post: 06-10-2004, 12:57 AM
  4. Any Computeach International Students/ex students??
    By stevey in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 03-26-2002, 04:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21