Hi can someone help me code this problem in C? Just started learning 2 months ago thanks.

Here is my attempt in C

include <stdio.h>

define GROUP_SIZE 6

define STEP_SIZE 7

struct Person { char dead; char name; };

int main() {

struct Person people[GROUP_SIZE];
int i, p, step, round;
char name, last_person;

p = -1;
step = 0;
round = 0;
name = 'a';

for(i = 0; i < GROUP_SIZE; i++) {
    people[i].dead = 0;
    people[i].name = name++;
}

while(round < GROUP_SIZE - 1) {

    p++;
    if(p == GROUP_SIZE) {
        p = 0;
    }

    if(people[p].dead) {
        continue;
    }

    if(step == 0) {
        printf("Starting round: %d\n", round);
        printf("--------------------\n");
    }

    step++;
    printf("Person: '%c' Count: %d\n", people[p].name, step);

    if(step == STEP_SIZE) {
        printf("Person %c is now dead, starting next round\n\n", people[p].name);
        people[p].dead = 1;
        round++;
        step = 0;
    }

}

printf("-----------------\n");
printf("The Nonary game has concluded\n");
for(i = 0; i < GROUP_SIZE; i++) {
    if(people[i].dead) {
        continue;
    }
    printf("Person %c is the winner.\n", people[i].name);
    break;
}

}

/r/learnprogramming Thread Parent