info@thistimebd.com

Friday 26th of April 01:40:21am

Write a user defined function that receives an integer array and find out average of the elements.

Write a user defined function that receives an integer array and find out average of the elements.



#include

using namespace std;


double func(int arr[], int n)

{

    int i,sum=0;



    for (i = 0; i < n; i++)

        sum=sum+arr[i];


       return sum/n;

}


int main()

{

    int arr[] = {10, 10, 10};

    int n = sizeof(arr) / sizeof(arr[0]);

    cout << "avg "<< func(arr, n);

    return 0;

}