Write a function which accepts an array of size n containing integer values and returns average of all values. Call the function from main program.

#include<stdio.h>

int avg(int [],int);

main()
{
    int a[100], n,i,avrg;
    printf("\nEnter number of terms=");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    avrg=avg(a,n);
    printf("\nThe average=%d",avrg);
}
int avg(int a[],int n)
{
    int i,s=0;
    for(i=0;i<n;i++)
    {
        s=s+a[i];
    }
    return s/n;
}

2 comments:

  1. this post was really helpful for me thankyou so much for posting that. I hope you will further post such type of important programs so that I can understand it well. Thankyou!\

    ReplyDelete