Find Average of the Elements of an Array C Program

How to write a Program to find average of the elements of an array in C Programming Language ?


 Array–pointer interchangeability

Solution:
//Program to find average of the elements of an array.
#include<stdio.h>
#include<conio.h>

void main() {

int arr[5] = {2, 4, 7, 9, 8};
int i = 0;
float avg = 0;

clrscr();

for(i = 0; i < 5; i++)
avg = avg + arr[i];

avg = avg / i;
printf("The average of the elements of the array is: %f", avg);

getch();
}


Learn More :