/* * https://rosettacode.org/wiki/100_doors#C */ #include int main() { char is_open[101] = { 0 }; int pass, door; /* do the 100 passes */ for (pass = 1; pass <= 100; ++pass) { for (door = pass; door <= 100; door += pass) { is_open[door] = !is_open[door]; } } /* output the result */ for (door = 1; door <= 100; ++door) { printf("door #%3d is %s.\n", door, (is_open[door]? "open" : "closed")); } return 0; }