26. Dynamic Sensor Buffer

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

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

    if (n < 1) {
        return 0;
    }

    // Write your dynamic buffer allocation code here
    int avg = 0;
    int *arrptr = new int[n];
    for(int i=0; i<n; i++){
        std::cin >> *(arrptr+i);
        avg += *(arrptr+i);
    }

    avg = avg / n;

    std::cout << avg << std::endl;
    return 0;
}

Solving Approach

 

 

 

 

 

Was this helpful?
Upvote
Downvote