I've been unsuccessfully trying to write a program to generate pascal triangle numbers and insert them into an 2D flexible array, but i still not getting it; any sugestions?
Printable View
I've been unsuccessfully trying to write a program to generate pascal triangle numbers and insert them into an 2D flexible array, but i still not getting it; any sugestions?
The formula for a Pascal Triangle element is:
Whereas n is the row and r is the element(left to right). ! is a factoral sign, which means to multiply that number times every number below it to 1. Like: 6! = 6*5*4*3*2*1 = 720. Puting this in code shouldn't be too hard. Putting it in an array sounds easy, because you could just take a two dimention array and have the row and element as the array subscript numbers. If you still need some coding help just reply back.Code:n!
--------
r!(n-r)!
Another way to generate pascal's numbers is to look at
1
1 2 1
1 3 3 1
1 4 6 4 1
Look at the 4 and the 6. It is clear that
4 = 1 + 3
6 = 3+3
Every number in pascal's triangle except for the boundary 1's are such that
pascal(row, col) = pascal(row-1, col-1) + pascal(row-1, col). You can implement a straitforward recursive soultion or by using the array not need recursion.
Just observe that 0! = 1, and not 0 :)
>2D flexible array
A 2D flexible array?
He probably means dynamic, it should be larger the higher number he inputs.Quote:
Originally posted by Shiro
>2D flexible array
A 2D flexible array?
PS: How do you represent pascals triangle in a "square" 2D array? hmmmmmmmm... :)
Thanks that's all i needed to know