How to create a pascal's triangle using a single dimension array with the last number specified?

Printable View

- 02-19-2003Priyankpascal's triangle
How to create a pascal's triangle using a single dimension array with the last number specified?

- 02-19-2003Polymorphic OOP
if you want to display the whole triangle up to that point then just start with 1 and build the rest of the rows from adding the appropriate columns from the previous rows (and 1's on the ends). If your just want a row then use combinations ( r! / ( c! * ( r - c )! ).

If you're storing all the rows of pascals triangle up to the one specified, just store the columns one by one in the array. When refering to the array you know that there is always 1 plus the row number amount of columns in that row so you can just use that knowledge to figure out where each row starts. - 02-19-2003Priyank
It doesn't work out succesfully

- 02-19-2003Polymorphic OOP
It should, unless you're doing it wrong :p

Post your code and we'll help find the mistake, but we won't do it all for you. - 02-19-2003Shadow12345
What is pascal's triangle? when you do the ! that means factorial right? i.e you start at the number and then recursively add one minus the number and add it to another variable until you get to zero?

5! = 5 + 4 + 3 + 2 + 1 right? I think I did this in 8th grade - 02-20-2003Priyank
Pascals triangle has got nothing do with factorials......

it is something like this:-

1

1 2 1

1 3 3 1

1 4 6 4 1

......

and it goes on and on......it works on the principle that a numer is the sum of digit exactly above it in the previous row and and the no before it. - 02-20-2003Polymorphic OOPQuote:

*Originally posted by Priyank*

**Pascals triangle has got nothing do with factorials......**

it is something like this:-

1

1 2 1

1 3 3 1

1 4 6 4 1

......

and it goes on and on......it works on the principle that a numer is the sum of digit exactly above it in the previous row and and the no before it.

EDIT: Shadow: No, factorial is multiplication not addition. You can use rows of pascals triagnle to figure out the coefficients of terms in expanded polynomials of the form (x + 1)^n. - 02-20-2003MagosQuote:

*Originally posted by Polymorphic OOP*

**You can use rows of pascals triagnle to figure out the coefficients of terms in expanded polynomials of the form (x + 1)^n.**

**Y**)^n

Code:`1`

1 1

1 2 1

1 3 3 1

1 4 6 4 1

1 5 10 10 5 1

(X + Y)^5 =

1 * X^5 * Y^0 +

5 * X^4 * Y^1 +

10 * X^3 * Y^2 +

10 * X^2 * Y^3 +

5 * X^1 * Y^4 +

1 * X^0 * Y^5

- 01-14-2011ijlalhayder
can anyone submit a proper code please.. thnQ..!

- 01-14-2011Fordy
Dont bump old threads