C Example: Seat Booking: 2D map, reserve, cancel and occupancy count
Represents seats as a 7×6 character matrix, '.' free and 'X' booked; reserve validates row/column bounds and occupancy, cancel only releases booked seats, and the program prints the map and counts free seats. Shows a 2D array as a state table with full bounds checking.
🖥 Run OnlineGCC 10.2 · C11 standard · click ▶ to run · Copy code
🖨 Reference OutputMatches the online run in a standard C11 environment
Ada R2C3 -> booked
Grace R2C3 -> taken
Linus R5C6 -> booked
Ken R10C3 -> invalid
Margaret R8C7 -> invalid
seat map:
1 2 3 4 5 6
R1 . . . . . .
R2 . . X . . .
R3 . . . . . .
R4 . . . . . .
R5 . . . . . X
R6 . . . . . .
R7 . . . . . .
cancel R1C2 -> ok
cancel R9C2 -> invalid
after cancel:
1 2 3 4 5 6
R1 . . . . . .
R2 . . . . . .
R3 . . . . . .
R4 . . . . . .
R5 . . . . . X
R6 . . . . . .
R7 . . . . . .
free seats: 41/42
🧩 Keep Learning