Left factorials: Difference between revisions
Content deleted Content added
added Mathematica |
Initial implementation in PL/I |
||
Line 466: | Line 466: | ||
<lang perl6>constant leftfact = 0, [\+] 1, [\*] 1..*;</lang> |
<lang perl6>constant leftfact = 0, [\+] 1, [\*] 1..*;</lang> |
||
(No significant difference in run time.) |
(No significant difference in run time.) |
||
=={{header|PL/I}}== |
|||
<lang PL/I>lf: procedure (n) returns (fixed decimal (31) ); |
|||
declare n fixed binary; |
|||
declare (s, f) fixed (31); |
|||
declare (i, j) fixed; |
|||
s = 0; |
|||
do i = n-1 to 0 by -1; |
|||
f = 1; |
|||
do j = i to 1 by -1; |
|||
f = f * j; |
|||
end; |
|||
s = s + f; |
|||
end; |
|||
return (s); |
|||
end lf; |
|||
declare n fixed binary; |
|||
do n = 0 to 10, 20 to 30; |
|||
put skip list ('Left factorial of ' || n || '=' || lf(n) ); |
|||
end; |
|||
end left_factorials;</lang> |
|||
Results:- |
|||
<pre> |
|||
Left factorial of 0= 0 |
|||
Left factorial of 1= 1 |
|||
Left factorial of 2= 2 |
|||
Left factorial of 3= 4 |
|||
Left factorial of 4= 10 |
|||
Left factorial of 5= 34 |
|||
Left factorial of 6= 154 |
|||
Left factorial of 7= 874 |
|||
Left factorial of 8= 5914 |
|||
Left factorial of 9= 46234 |
|||
Left factorial of 10= 409114 |
|||
Left factorial of 20= 128425485935180314 |
|||
Left factorial of 21= 2561327494111820314 |
|||
Left factorial of 22= 53652269665821260314 |
|||
Left factorial of 23= 1177652997443428940314 |
|||
Left factorial of 24= 27029669736328405580314 |
|||
Left factorial of 25= 647478071469567844940314 |
|||
Left factorial of 26= 16158688114800553828940314 |
|||
Left factorial of 27= 419450149241406189412940314 |
|||
Left factorial of 28= 11308319599659758350180940314 |
|||
Left factorial of 29= 316196664211373618851684940314 |
|||
Left factorial of 30= 9157958657951075573395300940314 |
|||
</pre> |
|||
=={{header|Python}}== |
=={{header|Python}}== |