26. Dynamic Sensor Buffer

Back To All Submissions
Previous Submission
Next Submission
#include <iostream>
using namespace std;

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

    if (n < 1) {
        return 0;
    }

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

    int avg = sum/n;
    cout << avg;
    delete[] arr;
    return 0;
}

Solving Approach

 

 

 

 

 

Was this helpful?
Upvote
Downvote