![]() |
VOOZH | about |
In this article, we will learn how to calculate the average of all elements of an array using a C program.
The simplest method to calculate the average of all elements of an array is by using a loop. Let's take a look at an example:
3.00
Explanation: This method iterates through the entire array to find the sum of all elements and then divides the sum by the total number of elements to calculate the average.
This approach can also be implemented using recursion as shown below.
This method computes the average of the first n-1 elements using a recursive call for each element of the array. Then it combines it with the average of last element to find the overall average.
3.00