How to write a program of sum and average of an array in C programming?

By | October 8, 2021

WAP for Average and Sum of Array Elements

#include<stdio.h>
#include<conio.h>
void main()
{
float sum=0,avg,a[50];
int i,j,n;
clrscr();
printf("Enter the size of array: ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the value for a[%d]: ",i);
scanf("%f",&a[i]);
}
for(j=0;j<n;j++)
{
sum = sum+a[j];
}
avg = sum/n;
printf("Sum of array is: %f \n", sum);
printf("Average of array is: %f", avg);
getch();
}

Output:

How to write a program of sum and average of an array in C programming?

Leave a Reply

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