# Get the average of all elements in a double array

Page 1 of 1

## 2 Replies - 230 Views - Last Post: 10 February 2011 - 05:44 AM

### #1 RodgerB

• D.I.C Lover

Reputation: 66
• Posts: 2,284
• Joined: 21-September 07

# Get the average of all elements in a double array

Posted 10 February 2008 - 01:45 AM

Description: 1) Copy and paste this function into a class. 2) Read how to call the function.Calculates and returns the Mean of a double array.
```///
/// Calculate the average of all elements in a double array.
///
/// The double array to get the
/// average from.
/// The average of the double array
double getAverageFromDoubleArray(double[] dblArray)
{
double dblResult = 0;
foreach (double dblValue in dblArray)
dblResult += dblValue;
return dblResult / dblArray.Length;
}

// Example Usage:
double[] lolz = { 1, 1, 1, 2 };
MessageBox.Show(getAverageFromDoubleArray(lolz).ToString());
```

Is This A Good Question/Topic? 0

## Replies To: Get the average of all elements in a double array

Reputation: -1
• Posts: 3
• Joined: 10-February 11

## Re: Get the average of all elements in a double array

Posted 10 February 2011 - 05:43 AM

To get the source code for calculating the sum and average of all the elements of the array is available at: http://bitsbyta.blog...ments-cnet.html

Reputation: -1
• Posts: 3
• Joined: 10-February 11

## Re: Get the average of all elements in a double array

Posted 10 February 2011 - 05:44 AM

To get the source code for calculating the sum and average of all the elements of the array is available at: http://bitsbyta.blog...ments-cnet.html More related source codes available at: http://bitsbyta.blogspot.com/