Here I coded the second approach and got the same answer. (I realize it's far from optimized.)
#include <stdio.h>
void printlockers(void);
static int lockers[100];
int main(){
// initialize lockers, 0 is closed, 1 is open
for (int i=0;i<100;i++)
lockers[i]=0;
for (int i=1; i<=100; i++) // which locker
for (int j=1; j<=100; j++) // which student
if (!(i%j))
lockers[i-1]=(lockers[i-1]+1)%2;
printlockers();
return 0;
}
void printlockers(void){
for (int i=0; i<100; i++)
printf("%1d",lockers[i]);
printf("\n");
}