C programming assignment (with arrays)
I am new to C and i just learned how to use arrays. I have to complete the task below:
There are 100 doors (numbered 1 through 100) and 100 students
(numbered 1 through 100) waiting in a line. Initially, all the doors are closed. 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? Write a C program that mimics this experiment and prints the numbers of the doors that remain open at the end.
I am stuck on how to know which door is in what state. This is what I have now.
Code:
#include <stdio.h>
int main(void)
{
int i,x=0,j,door,k=1,d[100],s[100];
for (i=1;i<100;i++)
d[i]=i;
for(k=1;k<100;k++)
s[k]=k;
k=1;
for(i=1;i<=100 || k==100;i++)
{
j=d[i]%s[k];
for(;i==100;k++)
i=1;
if(j==0)
}
return;
}
If I pasted the code wrong I sincerely apologize and I will try again. As you can see the code isn't fully finished. I think I am on the right track I just can't figure out how to know what happens to which door. Thanks for any help.