Write a C Program to calculate the Average of an array elements where the elements are received as
input.
#include<stdio.h>
int main(){
int n;
printf("Enter the number of elements: ");
scanf("%d", &n);
printf("Enter %d elements of the array\n", n);
int i;
int arr[n];
int sum = 0;
for(i=0; i<n; i++){
scanf("%d", &arr[i]);
sum += arr[i];
}
printf("The average is: %d", (sum/n));
}
Comments
Leave a comment