# Find mean of an Array

Find mean of an Array” is a basic problem of array data structure. Here, we are given an array of size ‘n’ and our task is to find and print the mean of the array.

Mean of array = (sum of all the elements of the array) / n.

Example:

```INPUT:
Arr = {11, 12, 13, 14, 15}
OUTPUT:
13
Explanation:
Mean = (11+12+13+14+15)/5 = 13```

The steps to find the mean of the array are as follows:

1. Scan array size(N).
2. Scan array elements.
3. Compute the sum of all the elements of array by
4. Divide the sum by N.
5. Print the result.

C++ Program to find the mean of the array is as follows:

```/* Program to find the mean of the array */
#include<bits/stdc++.h>
using namespace std;
int main()
{
/* Scan array size */
int n;
cout<<"Enter array size:";
cin>>n;

/*Scan array elements */
int arr[n];
cout<<"\nEnter array elements: ";
for(int i = 0; i < n; i++)
cin>>arr[i];

/* Compute sum */
int sum = 0;
for(int i = 0; i < n; i++)
sum = sum + arr[i];

/* Divide sum by n */
float mean;
mean = sum/n;

/* Printing result */
cout<<"\nThe mean of the array is "<<mean;
}
```
```OUTPUT:
Enter array size: 5
Enter array elements:  11 12 13 14 15
The mean of the array is 13

Time Complexity:
O(n), where n is the size of the array```

Related Posts: