- #1
Smiles302
- 27
- 0
Homework Statement
I need to write a program (which passes by reference) to find the standard deviation of an array of numbers.
Homework Equations
http://en.wikipedia.org/wiki/Standard_deviation < the simple standard deviation formula is the one I am using.
I've tested the program and the only bit not working is this (mean - x)^2
The Attempt at a Solution
for(int i = 0; i < num; i++)
{
std = (mean - xArray);
if (std < 0)
{
std = std*(-1);
}
std = (std*std);
}
Should this loop give me this equation:
The array is {12, 4, 5, 3, 4, 0, 1, 8, 2, 3};
And my mean is 4.2.
(12 - 4.2)^2 + (4 - 4.2)^2 + (5 - 4.2)^2 + (3 - 4.2)^2 + ( 4 - 4.2)^2 + (0 - 4.2)^2 + (1 - 4.2)^2 + ( 8 - 4.2)^2 + (2 - 4.2)^2 + (3 - 4.2)^2.
This should give me 111.6 but it keeps giving me the answer 1.44
Can anyone tell me what my program is going to get 1.44 =/