Pascal's triangle: Difference between revisions

Content added Content deleted
(Updated second D entry)
Line 1,403: Line 1,403:
1 5 10 10 5 1
1 5 10 10 5 1


</pre>
Another way to get a formated pascals triangle is to use the convolution method:
<pre>>>
x = [1 1] ;
y = 1;
for k=8:-1:1
fprintf(['%', num2str(k), 'c'], zeros(1,3)),
fprintf('%6d', y), fprintf('\n')
y = conv(y,x);
end
</pre>
The result is:
<pre>>>

1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
</pre>
</pre>