Cumulative standard deviation: Difference between revisions

m
→‎show running sums: added/changed whitespace.
(→‎{{header|Perl}}: shorter perl version)
m (→‎show running sums: added/changed whitespace.)
Line 3,458:
<lang rexx>/*REXX program calculates and displays the standard deviation of a given set of numbers.*/
parse arg # /*obtain optional arguments from the CL*/
if #='' then #= 2 4 4 4 5 5 7 9 /*None specified? Then use the default*/
n= words(#); $= 0; $$= 0; L= length(n) /*N: # items; $,$$: sums to be zeroed*/
/* [↓] process each number in the list*/
do j=1 for n; _=word(#,do j); $ =$1 +for _n
_= word(#, j); $= $ + $$=$$ + _**2
say ' item' right(j,L)":" right(_,4) ' average=' left( $/j,12),$= $$ + _**2
' say standard deviation=' item' sqrtright($$/j, -L)":" right(_, 4) ' average=' left($/j, 12)**2),
end /*j*/ ' standard deviation=' sqrt($$/j - ($/j)* [↑] prettify output with whitespace*/2)
end /*j*/ /* [↑] prettify output with whitespace*/
say 'standard deviation: ' sqrt($$/n - ($/n)**2) /*calculate & display the std deviation*/
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
sqrt: procedure; parse arg x; if x=0 then return 0; d=digits(); h=d+6; m.=9; numeric form