﻿<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
        <Header>
            <Title> Find standard deviation of elements in integer array </Title>
            <Description> Expansion snippet to calculate standard deviation of elements in an array.  </Description>
            <Author>Microsoft Corporation</Author>
            <SnippetTypes>          
                <SnippetType> Expansion </SnippetType>
            </SnippetTypes>
        </Header>
        <Snippet>
            <Declarations>
                <Literal>
                    <ID> NumberArray </ID>
                    <Default> nArray </Default>
                    <ToolTip> Array containing element whose standard deviation is to be calculated. </ToolTip>
                </Literal>
            </Declarations>
            <Code Language="vjsharp" Format="CData"><![CDATA[
double dMeanValue = 0;
double tmpVar1 = 0;     

for (int i = 0; i < $NumberArray$.length; i++)
{
//Compute the sum of all values in the array
    dMeanValue = dMeanValue + $NumberArray$[i];
}
//Compute the mean of all values in the array
dMeanValue = dMeanValue / $NumberArray$.length;

System.out.println(" Mean Value :" + dMeanValue);

//Compute the standard deviation of all values in the array
for (int i = 0; i < $NumberArray$.length; i++)
{
    double tmpVar2 = $NumberArray$[i] - dMeanValue;
    tmpVar1 = tmpVar1 + tmpVar2;
}
tmpVar1 = java.lang.Math.pow(tmpVar1, 2);
double stdDeviation = tmpVar1 / $NumberArray$.length;
stdDeviation = java.lang.Math.sqrt(stdDeviation);
$selected$ $end$
]]>
</Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>
