40. State Machine Using Function Pointers

You are simulating a system boot-up sequence using function pointers. 

There are 4 states:

void state_init()    { printf("Init"); }
void state_load()    { printf("Load"); }
void state_execute() { printf("Execute"); }
void state_exit()    { printf("Exit"); }

Your Task

  • Implement the function run_state_sequence(int start)
  • It should execute three states in sequence, starting from the given start index:
    • If start = 1 → print Load, Execute, Exit
    • If start = 3 → wrap around → print Exit, Init, Load
  • ✅You must use a function pointer array
  • ❌ Do not use if or switch-case
     

Constraints

  • start ∈ [0, 3]
  • Always execute exactly three states
  • Output each state on a new line


Example-1

Input: 0
Output:
Init
Load
Execute


Example-2

Input: 2
Output:
Execute
Exit
Init


Example-3

Input: 3
Output:
Exit
Init
Load



 

Loading...

Input

0

Expected Output

Init Load Execute