Program to find sum and average of given elements in an array

Program to find sum and average of given elements in an array


Program:


#include<stdio.h>
void main()
{
float a[5],sum=0,avg;
int i;
printf("Enter float array: \n");
for(i=0;i<5;i++)
{
scanf("%f",&a[i]);
sum=a[i]+sum;
}
avg=sum/5;
printf("\nSum is: %f",sum);
printf("\nAvg is: %f",avg);
}

Output:






No comments:

Post a Comment