Practice

Rainfall Dry-Spell Report

2026/May/June·Variant 2·Q10·[15 marks]
HARDArrays

Read 10 daily rainfall totals in millimetres into array Rainfall. Then output:

  • total rainfall for the period in centimetres, rounded to 2 decimal places (divide millimetres by 10)
  • mean daily rainfall in millimetres, rounded to 4 decimal places
  • how many days had no rain
  • the longest run of consecutive dry days
  • Drought if that longest run is 4 days or more, otherwise No drought

Input: 10 real numbers (mm of rain each day). Output: Five lines in the order above.

Example:

Input:  2
        0
        0
        0
        0
        5
        0
        3
        1
        4
Output: Total: 1.5 cm
        Average: 1.5 mm
        Dry days: 5
        Longest dry spell: 4
        Drought

Sample Test Cases

Test 1: Four-day dry spell triggers drought
Inputs: 2, 0, 0, 0, 0, 5, 0, 3, 1, 4
Expected: Total: 1.5 cm Average: 1.5 mm Dry days: 5 Longest dry spell: 4 Drought
Test 2: Rain every day
Inputs: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
Expected: Total: 1 cm Average: 1 mm Dry days: 0 Longest dry spell: 0 No drought