![]() |
VOOZH | about |
Mean is the average of the given numbers which is calculated by dividing the sum of given numbers by the total count of numbers.
Example:
Find the mean of the given numbers 2, 4, 4, 4, 5, 5, 7, and 9?
👁 Image Mean of 2, 4, 4, 4, 5, 5, 7, 9 Solution:
- Step1: Take sum of all numbers, 2 + 4 + 4 + 4 + 5 + 5 + 7 + 9 = 40
- Step2: Divided sum by the total count of numbers, 40/ 8 = 5
Given the n size array, find its mean.
Examples:
Input : {1, 3, 4, 2, 6, 5, 8, 7}
Output : Mean = 4.5
Explanation: Sum of the elements is 1 + 3 + 4 + 2 + 6 + 5 + 8 + 7 = 36, Mean = 36/8 = 4.5Input : {4, 4, 4, 4, 4}
Output : Mean = 4
Approach:
Formula used:
Mean of an array = (sum of all elements) / (number of elements)
Follow the steps below for implementation:
Below is the implementation of the above approach
Mean = 4.5
Time Complexity: O(n), Where n is the size of the given array.
Auxiliary Space: O(1), As no extra space is used.
Basic Program related to Mean