21. Dynamic Sensor Buffer

Your firmware needs to capture a burst of sensor readings.
The number of readings (n) is not known at compile time, so a dynamic buffer must be allocated using new[].

Steps:

  1. Read integer n — number of samples to store.
  2. If n is less than 1, terminate the program.
  3. Dynamically allocate an integer array of size n using new[].
  4. Read n sensor readings into the buffer.
  5. Compute the average sensor value using integer division.
  6. Print the average.
  7. Release the allocated memory using delete[].

 

Example 1

Input:

5
10 20 30 40 50

Output:

30

 

Example 2

Input:

4
100 100 100 100

Output :

100

 

Constraints:

  • Use new[] and delete[]
  • Do not use STL containers or static arrays
  • Assume 1 ≤ n ≤ 1000
  • Sensor readings are integers

 

 

Loading...

Input

5 10 20 30 40 50

Expected Output

30