# How to calculate standard deviation

• 03-09-2009
hobilla
How to calculate standard deviation
I have no idea how to make a program that will calculate the standard deviation of 10 numbers. I dont even know the formula. I just learned of arrays the day before and our professor gave this assignment.

Any help??
• 03-09-2009
laserlight
At the very least, search the Web for a formula that you can implement.
• 03-09-2009
vart
• 03-09-2009
hobilla
i got the formula

but no idea where to start and how to solve this problem..!>!>>!~
• 03-09-2009
laserlight
So, what is the formula that you intend to use?
• 03-09-2009
vart
Quote:

Originally Posted by hobilla
i got the formula

but no idea where to start and how to solve this problem..!>!>>!~

you said you learned arrays

Start with the program that fills array of 10 floats (from stdin) and then prints them out to the stdout
• 03-09-2009
nonoob
Unless I'm missing something, you have to rip through the array to first calculate the average of all the elements. Start with that and print out the average. Hand-calculate it also to double check. Then loop through again applying the formula. Maybe there's a way to do it all at once.
• 03-10-2009
hobilla
it is not being helpful to me..
sorry guys but im really having trouble with it.
the formula i got is...http://en.wikipedia.org/wiki/Standard_deviation from here..

now can sum1 help me
• 03-10-2009
laserlight
That article provides several versions of the formula. Which do you intend to implement?
• 03-10-2009
OK, let's get your program started. Post it with the headers: stdio.h.

Let's use the Wikipedia set of numbers so we'll be sure when it's right or wrong:

Code:

`int a[8] = {2,4,4,4,5,5,7,9};`
I'll refer to the first formula (the easiest one).

Using a for loop, how would you calculate the average (median) of these numbers?

You have great timing - I just finished putting together a program, from the Wikipedia site!
Quite amazing coincidence, since the thread had drifted to the second page of the forum.

Edit:
This is a very simple formula, so don't let the math give you a headache - it's ez:

1) Go thru the list of numbers in the array, and add them all up
2) Divide by the number of numbers that you have - in our example it's 40/8 = 5, which is our Median or Average
3) Now subtract that average, from all those numbers in the same list, and
4) Square the sum or those numbers you got in #3, above
5) Now take the sqrt() of that number you got in #4. That's the standard deviation.

So it's really just using simple arithmetic, except for the square root right at the last step.
• 03-13-2009
hobilla
i get the steps. Thanks. But no idea of how to put it in programming language..

help
• 03-13-2009
Quote:

Originally Posted by hobilla
i get the steps. Thanks. But no idea of how to put it in programming language..

help

Well, you'll need to include a standard header file, and put in your main() function. Then declare some variables - some integers and two doubles.

You'll need a for or while loop to make that addition of all the numbers, so you can find the average.

You can find for and while loops sprinkled all over the net, including this very forum.

You need to seriously get off your arse and get *doing*, however. Your helpless act has worn thin, already.

Post what you can do. We can help you with the rest of it, but no assistance should be given, if you aren't willing to work on this, and show some actual effort.

Despite what it may sound like, this is in fact, a trivial program.
• 03-14-2009
brewbuck
Quote:

Originally Posted by hobilla
I have no idea how to make a program that will calculate the standard deviation of 10 numbers. I dont even know the formula. I just learned of arrays the day before and our professor gave this assignment.

Any help??

You don't need an array if you use the "calculator method."

sqrt((sum_of_squares - square_of_sums / N) / (N-1))
• 03-14-2009
BEN10
Quote:

i get the steps. Thanks. But no idea of how to put it in programming language..

help

show us whatever you've done so far then we can get your program to run.