I'm trying to create a function that, given a row and column, will calculate the value at that position in Pascal's Triangle.
Example:
val = GetPasVal(3, 2); // returns 2
So here I'm specifying row 3, column 2, which as you can see:
1
1 1
1 2 1
...should be a 2.
Use the above code to print out your pascal triangle and thereby modify the code. The first 10 should look like:
The GetPasVal method will calculate all the numbers in the Pascal's Triangle up to the point that you will give (height) and after that the method will return the value of the index on that row(width). This is something you can use. It's quite simple. You just have to use a jagged array.
There is a formula from Combinations for working out the value at any place in Pascal's triangle:
It is commonly called
n choose k
and written like this:Notation:
n choose k
can also be writtenC(n,k)
,nCk
.https://www.mathsisfun.com/pascals-triangle.html
The Pascal's triangle contains the Binomial Coefficients C(n,k); There is a very convenient recursive formula
You can use this formula to calculate the Binomial coefficients.
Using Armen's equation the recursive code for implementing pascals triangle will be like below: