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/