Catalan numbers/Pascal's triangle: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 44: | Line 44: | ||
{{out}} |
{{out}} |
||
<pre>1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845 </pre> |
<pre>1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845 </pre> |
||
=={{header|Icon}} and {{header|Unicon}}== |
|||
The following works in both languages. It avoids computing elements in Pascal's triangle |
|||
that aren't used. |
|||
<lang unicon>link math |
|||
procedure main(A) |
|||
limit := (integer(A[1])|15)+1 |
|||
every i := 2*seq(0)\limit do write(right(binocoef(i,i/2)-binocoef(i,i/2+1),30)) |
|||
end</lang> |
|||
Sample run: |
|||
<pre> |
|||
->cn |
|||
1 |
|||
2 |
|||
5 |
|||
14 |
|||
42 |
|||
132 |
|||
429 |
|||
1430 |
|||
4862 |
|||
16796 |
|||
58786 |
|||
208012 |
|||
742900 |
|||
2674440 |
|||
9694845 |
|||
-> |
|||
</pre> |
|||
=={{header|MATLAB}} / {{header|Octave}}== |
=={{header|MATLAB}} / {{header|Octave}}== |