> A) Given a column and row print the relevant number within Pascal's triangle e.g. pascal(0,2) = 1 pascal(1,2) = 2 pa

A) Given a column and row print the relevant number within Pascal's triangle e.g. pascal(0,2) = 1 pascal(1,2) = 2 pa

Posted at: 2014-12-18 
For reference Pascal's triangle can be visualized:

1

1 1

1 2 1

1 3 3 1

1 4 6 4 1

...

The formula for pascal(k, n)

= n! / ((n-k)! k!)

You need the factorial function first. Here is one implementation in c:

int factorial(int n) {

return n == 0 ? 1 : n * factorial(n - 1);

}

Then you can define your pascal function:

int pascal(int k, int n) {

return factorial(n) / (factorial(n-k) * factorial(k));

}

This number is also called "n choose k", or the number of combinations of n things taken k at a time. The formula is n!/(k!)(n-k)! where n! means the factorial of n, n*(n-1)*(n-2)*(n-3)...(1). The factorial of 5 is 120.

Thus pascal(5,2) = 10.

>

> John (gnujohn)

For reference Pascal's triangle can be visualized:

1

1 1

1 2 1

1 3 3 1

1 4 6 4 1

...