C Program to Find Sum and average of Array Elements
#include <stdio.h>
#include<conio.h>
main()
{
int i, sum=0,n;
float avg=0;
printf("Enter how many numbers\n");
scanf("%d",&n);
int a[n];
printf("Enter %d number\n",n);
for (i=0;i<n;i++)
{
scanf("%d",&a[i]);
sum=sum+a[i];
}
avg=sum/n;
printf("\n sum of an array=%d",sum);
printf("\n Average of an array=%f",avg);
getch();
}
OUTPUT:
Note: In above program number are input in an array according to the user requirement and display their sum and average.
You may also read:
No comments:
Post a Comment