Numbers with equal rises and falls: Difference between revisions

m
→‎{{header|REXX}}: added commaization to output numbers.
(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 /*initilizeinitialize the rise/fall database. */
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 ' commas(n)th(n) " number is: " commas($ ) /*display the show Nth number#.*/
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); _= /*display a line; nullify a new line. */
end /*o*/ /* [↑] display 20 numbers to a line.*/
 
if _\=='' then say substr(_, 2); return /*handle any residual numbers in list. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
thcommas: parse arg th_; returndo th||wordc=length('th_)-3 st ndto rd',1+(th//10)*(th//100%10\ by -3; _==1)*insert(th//10<4',', _, c))</lang>; end; return _
th: parse arg th; return word('th st nd rd',1+(th//10)*(th//100%10\==1)*(th//10<4))</lang>
{{out|output|text=&nbsp; when using the default input:}}
<pre>
Line 664 ⟶ 665:
{{out|output|text=&nbsp; when using the input of: &nbsp; &nbsp; <tt> -10000000 </tt>}}
<pre>
the 10000000th10,000,000th number is: 4190900241,909,002
</pre>