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 *ptr= new int[n];
    int temp;
  for(int j=0;j<n;j++){
    cin>>temp;
    *(ptr+j)=temp;
  }
  int sum;
  for(int i=0;i<n;i++){
     sum=sum+*(ptr+i);
  }

    cout<<(sum/n);
    delete ptr;
}

Solving Approach

 

 

 

 

 

Upvote
Downvote
Loading...

Input

5 10 20 30 40 50

Expected Output

30