Seats (More)
Problem to Solve
A certain nearby theater has N rows, with M seats in each row. Mavid Dalan, the theater manager, wants to print a seating chart showing the seat numbers for each row, but this time, he doesn’t want to number the aisle seats. Suppose every Xth seat is adjacent to an aisle. If X is 4, the seating chart should omit seats 4, 8, 12, 16, and so on.
In a file called seats.c, in a folder called seats-more, write a C program that uses nested for loops to display the seating chart, skipping any seat number that’s a multiple of X. Seats should still be numbered consecutively (including the skipped aisle seats in the count), starting from 1.
For example, if the theater has 10 rows with 8 seats per row, and every 4th seat is an aisle seat, your program might behave as follows:
Enter number of rows: 10
Enter number of seats per row: 8
Enter aisle spacing: 4
Row 1: 1 2 3 5 6 7
Row 2: 9 10 11 13 14 15
Row 3: 17 18 19 21 22 23
Row 4: 25 26 27 29 30 31
Row 5: 33 34 35 37 38 39
Row 6: 41 42 43 45 46 47
Row 7: 49 50 51 53 54 55
Row 8: 57 58 59 61 62 63
Row 9: 65 66 67 69 70 71
Row 10: 73 74 75 77 78 79
Notice that seats 4, 8, 12, …, 80 (every multiple of 4) are omitted entirely from the chart, while every other seat number is still printed, still lined up in its usual column.
Requirements
- Prompt the user for the aisle spacing, X, in addition to the number of rows and seats per row.
- If the user enters a number less than 1 for either input, you should re-prompt the user until they give you a valid input.
- The number of seats per row must be evenly divisible by the aisle spacing.
- If number of seats per row is not divisible by aisle spacing (remainder when dividing is 0), re-prompt the user for the aisle spacing until it does.
- Omit any seat number that is a multiple of X from the printed chart, while still leaving its column blank (rather than shifting later seats to fill the gap).
- The program should work correctly if the number of rows, seats per row, and aisle spacing are changed.
Hints
- Start from the Less version.
- Add a prompt for the aisle spacing.
- Decide, for each seat, whether to print it.
- Keep the columns aligned, printing spaces when needed.
Demo
$ ./seats
Enter number of rows: 3
Enter number of seats per row: 6
Enter aisle spacing: 3
Row 1: 1 2 4 5
Row 2: 7 8 10 11
Row 3: 13 14 16 17
Here’s another example, this time with two aisles in every row:
$ ./seats
Enter number of rows: 2
Enter number of seats per row: 12
Enter aisle spacing: 4
Row 1: 1 2 3 5 6 7 9 10 11
Row 2: 13 14 15 17 18 19 21 22 23
How to Test
Does your code work as prescribed when you input:
- An aisle spacing of
1(every seat is an aisle seat)? - An aisle spacing that equals the number of seats per row (no seat is ever an aisle seat)?
- An aisle spacing that does not evenly divide the number of seats per row (you should be re-prompted)?
- A small number of rows and seats, like
3and6, with a small aisle spacing like3? - A large number of rows and seats, like
20and20, to confirm alignment holds as seat numbers grow larger? - Seat numbers with differing numbers of digits, to confirm blank columns and numbers both still line up?
Correctness
check50 cs50/problems/2026/fall/seats/more
Style
style50 seats.c
How to Submit
After you submit, wait a few minutes and then be sure to check your autograder results. If you see SUBMISSION ERROR: missing files (0.0/1.0), MissingFilesError, or the like, it means your file was not named exactly as prescribed (or you uploaded it to the wrong problem). Correctness in submissions entails everything from reading the specification, writing code that is compliant with it, and submitting files with the correct name. If you see this error, you should resubmit right away, making sure your submission is fully compliant with the specification. The staff will not adjust your filenames for you after the fact!
- Download your
seats.cfile by control-clicking or right-clicking on the file in your codespace’s file browser and choosing Download. - Go to CS50’s Gradescope page.
- Click Problem Set 1: Seats (More).
- Drag and drop your
seats.cfile to the area that says Drag & Drop. Be sure it has that exact filename! If you upload a file with a different name, the autograder likely will fail when trying to run it. Ensuring you have uploaded files with the correct filename is your responsibility! - Click Upload.
You should see a message that says “Problem Set 1: Seats (More) submitted successfully!”
Don’t forget that, starting this week, problems will be graded along the axis of Design also, which is done manually by your TF after the submission deadline. The autograder only awards a portion of the available points, and the rest will be awarded at the discretion of your TF when providing qualitative feedback.