VOOZH about

URL: https://www.geeksforgeeks.org/c/c-program-to-calculate-the-average-of-all-elements-of-an-array/

⇱ C Program to Calculate Average of an Array - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

C Program to Calculate Average of an Array

Last Updated : 23 Jul, 2025

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:


Output
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.

Using Recursion

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.


Output
3.00
Comment
Article Tags: