Practice

Count Students by Age Group

2022/Feb/Mar·Variant 2·Q2(a)·[8 marks]
MEDIUMLoops

Read 10 student ages. Count and output how many are:

  • aged 7 to 11 (i.e. ≥ 7 AND < 12)
  • aged 12 to 17 (i.e. ≥ 12 AND < 18)
  • aged 18 or over

Output the three counts on separate lines in that order.

Source: Inspired by 2022 Feb/Mar Variant 2 Q2(a)(b)

Input: 10 integers — the student ages. Output: Three lines — count of 7–11, count of 12–17, count of 18+.

Example:

Input:  8 10 13 16 20 25 7 12 18 11
Output: 4
        3
        3
Premium is coming soon. All grading features are currently unlocked.

Sample Test Cases

Test 1: Mixed ages
Inputs: 8, 10, 13, 16, 20, 25, 7, 12, 18, 11
Expected: 4 3 3
Test 2: All in 7-11
Inputs: 8, 9, 10, 11, 7, 8, 9, 10, 11, 7
Expected: 10 0 0
Test 3: All 18+
Inputs: 20, 21, 22, 23, 24, 25, 26, 27, 28, 29
Expected: 0 0 10
Press Ctrl+Enter to run your code
or Ctrl+Shift+Enter to grade