Program to calculate average of array in C

In this example, we declare array with integer elements and calculate average of it.

Calculate Average of Numbers using Array

	
#include <stdio.h>
int main() 
{
    int array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    int sum,loop;
    float avg;
    sum =avg= 0;
    for(loop=0;loop<10;loop++) 
    {
        sum=sum+array[loop];
    }
    avg=(float)sum/loop;
    printf("Average of array values is %.2f", avg);   
    return 0;
} 
	

Output :

	
        Average of array values is :: 5.50
	

Share your thoughts

Ask anything about this examples