Anonymous user
Anonymous recursion: Difference between revisions
m
→{{header|REXX}}: added whitespace, used a template for the output sections.
(→{{header|Smalltalk}}: oops) |
m (→{{header|REXX}}: added whitespace, used a template for the output sections.) |
||
Line 2,416:
numeric digits 1e6 /*in case the user goes ka-razy with X.*/
parse arg x . /*obtain the optional argument from CL.*/
if x=='' | x=="," then x=
w= length(x)
do j=0 for x+1 /*use the argument as an upper limit.*/
say 'fibonacci('right(j, w)") =" fib(j)
end /*j*/ /* [↑] show Fibonacci sequence: 0 ──► X*/
exit
/*──────────────────────────────────────────────────────────────────────────────────────*/
fib: procedure; parse arg z; if z>=0 then return .(z)
say "***error*** argument can't be negative."; exit
.: procedure; parse arg #; if #<2 then return #; return .(#-1) + .(#-2)</lang>
<pre>
fibonacci( 0) = 0
Line 2,449:
numeric digits 1e6 /*in case the user goes ka-razy with X.*/
parse arg x . /*obtain the optional argument from CL.*/
if x=='' | x=="," then x=
@.= .; @.0= 0; @.1=
w= length(x)
do j=0 for x+1 /*use the argument as an upper limit.*/
say 'fibonacci('right(j, w)") =" fib(j)
end /*j*/ /* [↑] show Fibonacci sequence: 0 ──► X*/
exit
/*──────────────────────────────────────────────────────────────────────────────────────*/
fib: procedure expose @.; arg z; if z>=0 then return .(z)
say "***error*** argument can't be negative."; exit
.: procedure expose @.; arg #; if @.#\==. then return @.#; @.#=.(#-1)+.(#-2); return @.#</lang>
=={{header|Ring}}==
|