C Examples Joseph Life Dead Game
# C Language Example - Josephus Life-Death Game
[ C Language Examples](#)
30 people are on a boat, which is overloaded. 15 people need to get off.
So they line up in a queue, and their position in the line is their number.
They count off, starting from 1. The person who counts to 9 gets off the boat.
This continues in a circle until only 15 people remain on the boat. Which numbers got off the boat?
## Example
#includeint c = 0; int i = 1; int j = 0; int a = {0}; int b = {0}; int main(){while(i<=31){if(i == 31){i = 1; }else if(c == 15){break; }else{if(b != 0){i++; continue; }else{j++; if(j != 9){i++; continue; }else{b = 1; a = j; j = 0; printf("Person number %d got off the boatn", i); i++; c++; }}}}}
Executing the above example, the output is:
Person number 9 got off the boatPerson number 18 got off the boatPerson number 27 got off the boatPerson number 6 got off the boatPerson number 16 got off the boatPerson number 26 got off the boatPerson number 7 got off the boatPerson number 19 got off the boatPerson number 30 got off the boatPerson number 12 got off the boatPerson number 24 got off the boatPerson number 8 got off the boatPerson number 22 got off the boatPerson number 5 got off the boatPerson number 23 got off the boat
[ C Language Examples](#)
YouTip