26 lines
1.1 KiB
Text
26 lines
1.1 KiB
Text
' [RC] Averages/Root mean square
|
|
|
|
SourceList$ ="1 2 3 4 5 6 7 8 9 10"
|
|
|
|
' If saved as an array we'd have to have a flag for last data.
|
|
' LB has the very useful word$() to read from delimited strings.
|
|
' The default delimiter is a space character, " ".
|
|
|
|
SumOfSquares =0
|
|
n =0 ' This holds index to number, and counts number of data.
|
|
data$ ="666" ' temporary dummy to enter the loop.
|
|
|
|
while data$ <>"" ' we loop until no data left.
|
|
data$ =word$( SourceList$, n +1) ' first data, as a string
|
|
NewVal =val( data$) ' convert string to number
|
|
SumOfSquares =SumOfSquares +NewVal^2 ' add to existing sum of squares
|
|
n =n +1 ' increment number of data items found
|
|
wend
|
|
|
|
n =n -1
|
|
|
|
print "Supplied data was "; SourceList$
|
|
print "This contained "; n; " numbers."
|
|
print "R.M.S. value is "; ( SumOfSquares /n)^0.5
|
|
|
|
end
|