code:
=================================
#include <iostream>
using namespace std;
float calculateAvg(int A[],int n);
int main() {
int size;
float result;
cout<<"Enter the size of array : ";
cin>>size;
int Arr[size];
cout<<"Enter the array elements: ";
for(int i=0;i<size;i++)
{
cin>>Arr[i];
}
//call average function
result=calculateAvg(Arr,size);
cout<<"The average of array is: "<<result;
}
float calculateAvg(int A[],int n)
{
float avg;
int sum=0;
for(int i=0;i<n;i++)
{
sum=sum+A[i];
}
avg=sum/n;
return avg;
}
please upvote
Get Answers For Free
Most questions answered within 1 hours.