How to calculate standard deviation

This is a discussion on How to calculate standard deviation within the C Programming forums, part of the General Programming Boards category; I have no idea how to make a program that will calculate the standard deviation of 10 numbers. I dont ...

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    9

    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??

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,448
    At the very least, search the Web for a formula that you can implement.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  4. #4
    Registered User
    Join Date
    Feb 2009
    Posts
    9
    i got the formula

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

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,448
    So, what is the formula that you intend to use?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    Quote Originally Posted by hobilla View Post
    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
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  7. #7
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,831
    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.

  8. #8
    Registered User
    Join Date
    Feb 2009
    Posts
    9
    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

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,448
    That article provides several versions of the formula. Which do you intend to implement?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  10. #10
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    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.
    Last edited by Adak; 03-10-2009 at 11:30 AM.

  11. #11
    Registered User
    Join Date
    Feb 2009
    Posts
    9
    i get the steps. Thanks. But no idea of how to put it in programming language..

    help

  12. #12
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by hobilla View Post
    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.

  13. #13
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,236
    Quote Originally Posted by hobilla View Post
    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))
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  14. #14
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C/C++ standard
    By confuted in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 07-06-2003, 03:22 AM
  2. Standard Deviation in C++
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 09-14-2001, 11:09 AM
  3. loops and I/O file.
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 09-09-2001, 09:41 AM
  4. standard language, standard compiler?
    By doubleanti in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 09-03-2001, 04:21 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21