#include <iostream>

int main() {
    int n;
    std::cin >> n;

    // 1. Check if n is valid
    if (n < 1) {
        return 0;
    }

    // 2. Dynamically allocate an integer array of size n
    int* sensorBuffer = new int[n];

    long long sum = 0;

    // 3. Read n sensor readings into the buffer and calculate sum
    for (int i = 0; i < n; ++i) {
        std::cin >> sensorBuffer[i];
        sum += sensorBuffer[i];
    }

    // 4. Compute the average sensor value using integer division
    int average = sum / n;

    // Print the average
    std::cout << average << std::endl;

    // 5. Release the allocated memory
    delete[] sensorBuffer;

    return 0;
}

Solving Approach

 

 

 

 

 

Upvote
Downvote
Loading...

Input

5 10 20 30 40 50

Expected Output

30