Practice

Average of Numbers in Array

2023/Feb/Mar·Variant 2·Q2(b)·[5 marks]
EASYArrays

Read N numbers (1 ≤ N ≤ 50) and store them in a 1D array. Use a single loop to compute the total, then output the integer average (using integer division).

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

Input: N on the first line, then N integers one per line. Output: The integer average (integer division — no decimals).

Example:

Input:  5
        10
        20
        30
        40
        50
Output: 30
Premium is coming soon. All grading features are currently unlocked.

Sample Test Cases

Test 1: Average of 5 numbers
Inputs: 5, 10, 20, 30, 40, 50
Expected: 30
Test 2: Average of 4 numbers
Inputs: 4, 2, 4, 6, 8
Expected: 5
Test 3: All same values
Inputs: 3, 9, 9, 9
Expected: 9
Press Ctrl+Enter to run your code
or Ctrl+Shift+Enter to grade