26. Dynamic Sensor Buffer

Back To All Submissions
Previous Submission
Next Submission
#include <iostream>

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

    if (n < 1) {
        return 0;
    }

    int* buf = new int[n];
    int sum{};

    for (size_t i{}; i<n; ++i) {
        int temp;
        cin >> temp;
        *(buf + n) = temp;
        sum += temp;
    }

    auto average = sum / n;

    cout << average;

    return 0;
}

Solving Approach

 

 

 

 

 

Was this helpful?
Upvote
Downvote