Calculate the Average of an Array of Integers in C1 min read

To find the average of a table, it is necessary to traverse all the cells of table of length n, from 1 to n and to memorize the sum in a variable “sum”. At the exit of the loop, we divide this sum that we calculate by traversing all the values of the array with the for loop on the length of the array.

This program allows you to browse and calculate the average of int numbers in C language. You will notice that we made a cast float, why? Because the variable “average” is of type float, so it must be assigned to a float. You can also use and store the division result in a double variable.



Leave a Comment