C program to find average of all elements of array

Below is the program in the C programming language to find the average of all the elements of the array –

/* C program to find the average of the elements of the array */
#include<stdio.h>
#include<conio.h>
void main()
{
     int ar[100],n,i,sum=0;
     float avg;
     
     printf("Enter the size of the array \n");
     scanf("%d",&n);
     
     printf("Enter the elements of the array to find their average \n");
     for(i=0;i<n;i++)
     {
           scanf("%d",&ar[i]);
           sum=sum+ar[i];
     }
     
     avg=(float)sum/n;
     printf(" Average is %f",avg);
     getch();
}

yashan has written 70 articles

2 thoughts on “C program to find average of all elements of array

Cancel reply

Leave a Reply to Parashuram

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>