Anonymous user
Numbers with equal rises and falls: Difference between revisions
m
→{{header|REXX}}: added commaization to output numbers.
Not a robot (talk | contribs) (Add C) |
m (→{{header|REXX}}: added commaization to output numbers.) |
||
Line 617:
append= n>0 /*a flag that is used to append numbers*/
n= abs(n) /*use the absolute value of N. */
call init /*
do j=1 until #==n; Lm= length(j) - 1
s= 0 /*initialize the sum of rises/falls. */
Line 631:
if append then call show /*display a list of N numbers──►term.*/
else say 'the '
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
init: @.= 0; do i=1 for 9; _= i' '; @._= 1; _= '0'i; @._= +1; end /*i*/
do i=10 to 99; parse var i a 2 b; if a>b then @.i= -1
else if a<b then @.i= +1
end /*i*/; #= 0; $=; return
/*──────────────────────────────────────────────────────────────────────────────────────*/
show: say 'the first ' commas(#) " numbers are:"; say; w= length( word($, #) )
_=; do o=1 for n; _= _ right( word($, o), w); if o//20\==0 then iterate
say substr(_, 2); _=
end /*o*/
if _\=='' then say substr(_, 2); return /*handle any residual numbers in list. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
th: parse arg th; return word('th st nd rd',1+(th//10)*(th//100%10\==1)*(th//10<4))</lang>
{{out|output|text= when using the default input:}}
<pre>
Line 664 ⟶ 665:
{{out|output|text= when using the input of: <tt> -10000000 </tt>}}
<pre>
the
</pre>
|