Hey, I have a question to solve.

There are 1000 lockers all in a row, all closed at first.

Starting at the second locker and going to all even no. lockers, open it if closed (and close it if open).

Then start at the 3rd locker (opening if closed, closing if open) and going to the 6th...9th...

Then starting at the 4th locker and going on. (4th, 8th, 12th...)

Then the 5th...going...

I'm suppose to know how many lockers are open and closed after going through all the recursions.

This is what I have so far

btw, what is "unreachable code?"

Code:#include <stdio.h> #include <conio.h> #define OPEN 1 #define CLOSE 0 #define LAST 1000 void main (void) { int locker[1001]; int close_count=0, open_count=0; int i, a, start, j, n, p, z=1; locker[0]=-1; for (i=1; i<=LAST; i++) locker[1]=0; for (start=2; start<=LAST; start++) { for (j=start; j<=LAST; j=((z++)*j)) { if (LAST%j==0) { for (n=j; j<=LAST; j++) { if (locker[j]==CLOSE) locker[j]=OPEN; if (locker[j]==OPEN) locker[j]=CLOSE;} } else {for (n=j; j<=((LAST%j)*j); j++) { if (locker[j]==CLOSE) locker[j]=OPEN; if (locker[j]==OPEN) locker[j]=CLOSE;} } } } for (a=1; a<=LAST; a++) { if (locker[a]==0) close_count++; if (locker[a]==1) open_count++; } printf ("Number of open lockers are %d", open_count); printf ("Number of close lockers are %d", close_count); }