Mean value from double array - CSharp System

CSharp examples for System:Array Calculation

Description

Mean value from double array

Demo Code

/// Department of Proteomics and Signal Transduction. All rights reserved.
using System.Collections.Generic;
using System;/* w w w . j  av a2s . c  o  m*/

public class Main{
        public static double Mean(double[] x)
        {
            int n = x.Length;
            if (n == 0)
            {
                return Double.NaN;
            }
            double sum = 0;
            for (int i = 0; i < n; i++)
            {
                sum += x[i];
            }
            return sum / n;
        }
}

Related Tutorials