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;
}
Step-by-step explanation:
This line declares the size (or length) of the array
int size;
This line prompts the user for the array length
cout<<"Length of array: ";
This gets the input from the user
cin >> size;
This dynamically declares the array as of double datatype
double *numDoubles = new double[size];
This declares and initializes sum to 0
double sum =0;
This prompts the user for elements of the array
cout<<"Array Elements: ";
The following iteration gets input from the user and also calculates the sum of the array elements
for(int i=0;i<size;i++){
cin>>numDoubles[i];
sum += numDoubles[i];
}
This deletes the array
delete [] myarray;
This calculates and prints the average of the array
cout<<"Average: "<<sum/size;