Dynamic Sensor Buffer

#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 *buffer = new int[n];

    int i=0;
    int total = 0;
    while(i<n){
        cin >> buffer[i];
        total+=buffer[i];
        i++;
    }
    double average = static_cast <double> (total) / n;

    cout << average;

    delete[] buffer;

    return 0;
}

Solving Approach

 

 

 

 

 

Upvote
Downvote
Loading...

Input

5 10 20 30 40 50

Expected Output

30