Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think this might yield a general solution. The first loop adds each element or number in the data array together. It is then divided by the total number of elements to create the mean.</p> <p><img src="https://i.stack.imgur.com/AQzUi.png" alt="Equation for the Mean"></p> <p>The second loop adds all of the numbers -- after the mean has been subtracted and the result squared -- together. Finally, this number is divided by one less than the total number of data entries before being square-rooted. As far as your equation is concerned, this should do the trick, I think.</p> <p><img src="https://i.stack.imgur.com/1eLPD.png" alt="Equation for Standard Deviation"></p> <pre><code>FOR i = 0 to N // Says to loop through each element of the array // from index 0 to index N, whatever that is sum = sum + X[i] // Adds the current value to the existing sum variable next i // Increment the index to add the next number ENDLOOP // Terminates the loop M = sum / N // Divides the sum by the total number, N, to get Mean FOR j = 0 to N // Says to loop through each element of the array // from index 0 to index N, using "j" this time sumOfSquares = sumOfSquares + ((X[j] - M)^2) // etc... next j ENDLOOP stdDev = sqrt(sumOfSquares / (N - 1)) </code></pre> <p>However, you really should put forth some effort into researching what a for-loop is before posting a question. Google search "for-loop pseudocode" and you're bound to get several results that will explain exactly what you need to do. A for-loop, like the two used here, are primarily used when you want to loop through a proceedure a known number of times, as in you have an exact number of times you wish to go through the loop.</p> <p>EDIT: Also, I'm not sure if you've been asked to pseudocode an entire program that say... actually prompts the user to input the data and everything. This code will ONLY calculate the standard deviation assuming it already has an array X filled and that the number of data entries is already stored in N.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload