HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
  1. Problems
  2. /A small theatre has 5 rows of 8 seats. The program marks booked seats…
EasyComputer ScienceHigh School (9–10)Computer Science › ProgrammingNumericalIGCSE

A small theatre has 5 rows of 8 seats. The program marks booked seats…

StemPy LabContributed by StemPy Lab

Try it on paper first. A hint, the key idea and the worked solution are here when you need them.

A small theatre has 5 rows of 8 seats. The program marks booked seats.

pseudocode
DECLARE Booked : ARRAY[1:5, 1:8] OF BOOLEAN
DECLARE Row : INTEGER
DECLARE Seat : INTEGER
DECLARE Free : INTEGER
FOR Row ← 1 TO 5
    FOR Seat ← 1 TO 8
        Booked[Row, Seat] ← FALSE
    NEXT Seat
NEXT Row
Booked[3, 6] ← TRUE
Booked[1, 1] ← TRUE
Booked[3, 6] ← TRUE
Free ← 0
FOR Row ← 1 TO 5
    FOR Seat ← 1 TO 8
        IF NOT Booked[Row, Seat]
          THEN
            Free ← Free + 1
        ENDIF
    NEXT Seat
NEXT Row
OUTPUT Free

How many elements does the array have? Which seat is Booked[3, 6]? What is output?

Check your answer

Work it out on paper, then type your number. The answer itself stays hidden.

Need a reminder? The key ideaShowHide

DECLARE Name : ARRAY[1:Rows, 1:Columns] OF TYPE has rows times columns elements. An element is Name[Row, Column]. Nested loops visit every element: the outer loop for the rows, the inner loop for the columns. A row total is set to zero inside the outer loop, before the inner one.

The worked solution

Have you tried it?

Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.

Step 1. The size. 5×8=405 \times 8 = 405×8=40 elements.

Step 2. The seat. Booked[3, 6] is row 3, seat 6.

Step 3. The count. Two different seats are booked: row 3 seat 6, and row 1 seat 1. Booking row 3 seat 6 a second time changes nothing. So 40−2=3840 - 2 = 3840−2=38 seats are free, and the output is 38.

Answer: 40 elements; row 3, seat 6; output 38.

Log in to save this for later
← All Problems
← A program tries to move everyone in a queue back one place, to make room at the front…Three teams play three games each. Points[Team, Game] holds the points of a team in a game… →
More onComputer Science › Programming

Discussion (0)

Log in to join the discussion.

Loading…

Learn it in

  1. Two-dimensional arrays and nested loopsArrays and Files in Pseudocode

More on this topic

  1. A long scenario question. A teacher has the names of 5 students in the file Names.txt, one name a…Hard
  2. Shopping.txt holds six lines: bread, rice, milk, eggs, tea and jam…Medium
  3. The file Best.txt holds one line: 120. What is output, and what does Best.txt hold afterwards, when…Easy
The nine squares of a board are input row by row: X, O, O, then X, X, X, then O, a dot for an empty…Hard
  • Three teams play three games each. Points[Team, Game] holds the points of a team in a game…Medium
  • All problems on this topic →