我想创建一个给定一个行和列的函数,将计算在杨辉三角的位置的值。
I'm trying to create a function that, given a row and column, will calculate the value at that position in Pascal's Triangle.
val = GetPasVal(3, 2); // returns 2
所以在这里我指定第3行,第2列,其中你可以看到:
So here I'm specifying row 3, column 2, which as you can see:
1
1 1
1 2 1
...应该是2。
...should be a 2.
我可以使用C或C ++或C#这样做; code或伪code AP preciated!
I can use C or C++ or C# to do this; code or pseudocode appreciated!
帕斯卡三角包含二项式系数 C( N,K); 有一个很方便的递推公式
The Pascal's triangle contains the Binomial Coefficients C(n,k); There is a very convenient recursive formula
C(n, k) = C(n-1, k-1) + C(n-1, k)
您可以用这个公式来计算二项式系数。
You can use this formula to calculate the Binomial coefficients.