Factorial: Difference between revisions
Content added Content deleted
(add TI-57) |
|||
Line 9,828: | Line 9,828: | ||
expr {round([::math::special::Gamma [expr {$n+1}]])} |
expr {round([::math::special::Gamma [expr {$n+1}]])} |
||
}</syntaxhighlight> |
}</syntaxhighlight> |
||
=={{header|TI-57}}== |
|||
The program stack has only 3 levels, so the recursive approach can be skipped. |
|||
{| class="wikitable" |
|||
! Machine code |
|||
! Comment |
|||
|- |
|||
| |
|||
Lbl 0 |
|||
STO 0 |
|||
Lbl 1 |
|||
RCL 0 |
|||
× |
|||
Dsz |
|||
GTO 1 |
|||
1 |
|||
= |
|||
R/S |
|||
RST |
|||
| |
|||
program factorial(x) // x is the display register |
|||
r0 = x |
|||
loop |
|||
multiply r0 by what will be in the next loop |
|||
decrement r0 and exit loop if r0 = 0 |
|||
end loop |
|||
complete the multiplication sequence |
|||
return x! |
|||
end program |
|||
reset program pointer |
|||
|} |
|||
=={{header|TorqueScript}}== |
=={{header|TorqueScript}}== |