Answer:
Answered in C++
#include <iostream>
using namespace std;
int main() {
int size;
cout<<"Length of array: ";
cin >> size;
double *numDoubles = new double[size];
double sum =0;
cout<<"Array Elements: ";
for(int i=0;i<size;i++){
cin>>numDoubles[i];
sum += numDoubles[i];
}
delete [] numDoubles;
cout<<"Average: "<<sum/size;
return 0;
}
Explanation:
This line declares the size (or length) of the array
<em> int size;
</em>
This line prompts the user for the array length
<em> cout<<"Length of array: ";
</em>
This gets the input from the user
<em> cin >> size;
</em>
This dynamically declares the array as of double datatype
<em> double *numDoubles = new double[size];
</em>
This declares and initializes sum to 0
<em> double sum =0;
</em>
This prompts the user for elements of the array
<em> cout<<"Array Elements: ";
</em>
The following iteration gets input from the user and also calculates the sum of the array elements
<em> for(int i=0;i<size;i++){
</em>
<em> cin>>numDoubles[i];
</em>
<em> sum += numDoubles[i];
</em>
<em> }
</em>
This deletes the array
<em> delete [] myarray;
</em>
This calculates and prints the average of the array
<em> cout<<"Average: "<<sum/size;
</em>