Write a C program to store N numbers in a one dimensional array and calculate its average with the help of the function.

#include<stdio.h>
void avg(int arr[], int n);
int main()
{
int n,i,a[100];
printf("Amount of numbers:");
scanf("%d",&n);
    printf("\n Enter the numbers:");
    for(i=0;i<n;i++)
    {
   scanf("%d",&a[i]);
}
avg(a,n);
}
void avg (int arr[], int n)
{
int i,sum=0;
float a;
for(i=0;i<n;i++)
sum+=arr[i];
a=(float)sum/n;
printf("the average is %f",a);
}


credit: Manoj Kumar Bhat

Comments

Popular posts from this blog