# 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:**

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

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

- Scan array size(N).
- Scan array elements.
- Compute the sum of all the elements of array by
- Divide the sum by N.
- 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; }

Enter array size: 5 Enter array elements: 11 12 13 14 15 The mean of the array is 13OUTPUT:O(n), where n is the size of the arrayTime Complexity:

**Related Posts:**

**Program to merge two sorted arrays.****Program to find missing number in an array.****Program to sort if array is sorted.****Program to print Alternate Elements of an Array.****Program to swap kth element from beginning to kth element from end in an Array.****Program to print all possible subarrays of the given array.****Program to print kth smallest and kth largest element of an Array.****Program to find equilibrium index of an Array.****Program to find majority element of an Array.**-
**Program to sort an Array of 0s and 1s.** **Program to Reverse an Array.****Program to count number of odd numbers and even numbers in an array.****Program to find absolute difference between sum of odd index elements and even index elements.****Program to find smallest and largest element of the array.****Program to count occurrences of a particular element in an array.****Program to search an element in an Array (Linear Search).****Program to Rotate Array Elements by ‘D’ positions.****Program to find most frequent element in an array.****Program to find pair in an array with given sum.****Program to find first repeating element of an array.**