Help me improve this algorithm please, as of now it is calulating the rows of Pascal's Triangle but I need it to calculate the colums and stop at (3,1).

for n:= 0 to k do
for m:= 0 to n do
if m=0 or m=n then A[n,m]:= 1
else
A[n,m]:=A[n-1,m-1] + A[n-1,m]

What exactly do you mean by "columns"? The same as in your code?

If so, perhaps it would help to stare at the cute animation over at Wikipedia: Pascal's Triangle.

You'll notice that you don't have to complete a whole row to skirt down just one "column".

Good luck!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.