A tiny state machine can switch between off and on with each event.

Toggle State

toggle_state.c
#include <stdio.h>

enum SwitchState {
    SWITCH_OFF,
    SWITCH_ON
};

enum SwitchState toggle(enum SwitchState state) {
    if (state == SWITCH_OFF) {
        return SWITCH_ON;
    }
    return SWITCH_OFF;
}

int main(void) {
    int presses = ;
    enum SwitchState state = SWITCH_OFF;

    for (int i = 0; i < presses; i++) {
        state = toggle(state);
    }

    printf("presses=%d state=%d\n", presses, state);
    return 0;
}
#include <stdio.h>

enum SwitchState {
    SWITCH_OFF,
    SWITCH_ON
};

enum SwitchState toggle(enum SwitchState state) {
    if (state == SWITCH_OFF) {
        return SWITCH_ON;
    }
    return SWITCH_OFF;
}

int main(void) {
    int presses = ;
    enum SwitchState state = SWITCH_OFF;

    for (int i = 0; i < presses; i++) {
        state = toggle(state);
    }

    printf("presses=%d state=%d\n", presses, state);
    return 0;
}
#include <stdio.h>

enum SwitchState {
    SWITCH_OFF,
    SWITCH_ON
};

enum SwitchState toggle(enum SwitchState state) {
    if (state == SWITCH_OFF) {
        return SWITCH_ON;
    }
    return SWITCH_OFF;
}

int main(void) {
    int presses = ;
    enum SwitchState state = SWITCH_OFF;

    for (int i = 0; i < presses; i++) {
        state = toggle(state);
    }

    printf("presses=%d state=%d\n", presses, state);
    return 0;
}
state An enum names each possible state instead of using unexplained integers.
event Each button press applies the same transition rule to the current state.