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

#1 RodgerB  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 66
  • View blog
  • 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

#2 Saad Bin Saulat  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • 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
Was This Post Helpful? 0
  • +
  • -

#3 Saad Bin Saulat  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • 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/
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1