Dynamic Sensor Buffer

#include <iostream>

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

    if (n < 1) {
        return 0;
    }

    // Write your dynamic buffer allocation code here
    int sum=0;
    int* buff = new int(n);
    for(int i=0;i<n;i++)
    {
        int val;
        std::cin >> val;
        *(buff+i) = val;
        sum += *(buff+i);
    }
    std::cout<<sum/n;
    delete buff;
    return 0;
}

Solving Approach

 

 

 

 

 

Upvote
Downvote
Loading...

Input

5 10 20 30 40 50

Expected Output

30