For the famous problem.
There are 100 people standing in a circle numbered from 1 to 100. The first person is having a sword and kills the the person standing next to him clockwise i.e 1 kills 2 and so on. Which is the last number to remain alive? Which is the last number standing?
In the following C code for this problem.
void main(){
int i=0, j; //i has the sword, j gets killed.
int a[N]={0}; //0=not killed
while(1){
if(i != N-1) j = i + 1;
else j = 0;
while(a[j])
if((j + 1) == N) j = 0; //loop back to 0
else j++; //skip over the killed people
if(i==j){ //if i is the only one left, stop
printf("\n\n\n%d is left!", i+1);
return;
}
a[j] = 1; //kill j
printf(" %d kills %d.", i+1, j+1);
if(j != N-1) i = j + 1;
else i=0;
while(a[i])
if((i + 1) == N) i = 0;
else i++;
}
}
Please tell me meaning of int a[N]={0};
//0=not killed in line no. 6 Thanks.