Example 4

Create a class that provides a method that recursively calculates the value n choose k denoted C(n, k). Use the following recursive definition for C(n, k).

 C(n,0) = 1

 C(n,n) = 1

 C(n,k) = C(n-1,k-1) + C(n-1,k),       for n>k>0

 

Create application that uses the first class to calculate Pascal’s Triangle for the number of levels input by the user (between 1 and 10). Use the Keyboard class to get numerical input from the user.

 

Example 5 

Create an application to calculate the leading coefficients for the formula (a + b)^n where n is a value input by the user. Use the Keyboard class to get numerical input from the user.