Anonymous user
Averages/Simple moving average: Difference between revisions
→{{header|REXX}}: changed some comments, added whitespace, changed indentations, used better DO loop separators. .
No edit summary |
(→{{header|REXX}}: changed some comments, added whitespace, changed indentations, used better DO loop separators. .) |
||
Line 2,780:
=={{header|REXX}}==
The same item list was used as for the ALGOL68 example.
<lang rexx>/*REXX program
parse arg p q n .
if p=='' then p=3
if q=='' then q=5
if n=='' then n=10
/*──────────────────────────────────────────build 1st half of the list. */
do j=1 for n%2 /*build beginning of the list,*/▼
do
/*──────────────────────────────────────────build 2nd half of the list. */
do k=n%2 to 1 by -1
j=j+1
▲ end /*k*/
/*──────────────────────────────────────────show an indented item list. */
▲ do i=1 for n /*show an indented item list. */
do i=1 for n
say left('',60) 'item'
end /*i*/
do m=1 for n /*OK the, let's start the SMA.*/▼
/*──────────────────────────────────────────perform a simple moving avg.*/
smaQ=sma(q,m) /* " "
say
" sma("
" sma("q')='left(sma(q,m),11) /* " " " " Q. */
▲ end /*m*/
end /*m*/
/*──────────────────────────────────SMA subroutine──────────────────────*/
sma: procedure expose @.; parse arg p,j;
do k=max(1,j-p+1) to j+p for p while k<=j; i=i+1
end
return s/i
</lang>
{{out}} using the defaults
<pre style="height:30ex">
|