Design and write a complete C program including adequate comments to compute C(n, r). This function is known as the choose function, and is defined as the number of r element subsets of an n element set. So C(5, 2) = 10 because there are ten possible two element subsets from a set of 5 elements. Similarly, C(4, 1) = 4, C(4, 4) = 1, and C(4, 0) = 1.
Mathematically the choose function is defined as:
C(n, r) = n! / (R! * (n - r)! )
Where n and r are positive integers (or zero), and "!" means factorial, so C(5, 2) = 5! / (2! * 3!) = 120 / (2 * 6) = 120 / 12 = 10. Note that 0! (zero factorial) is defined to be 1 (one).
You must use exactly and only the following four functions in your program whose prototypes are as shown, and each performs the following tasks only:
The program should compile perfectly (without errors) and execute without error.
The number of possible 5-card poker hands is C( 52, 5 ),
which equals 2598960.
Yet even thought this value will fit into a long (or a 4
byte int), it is likely that trying to compute
C( 52, 5 ) will cause an error or a system crash.
(If you don't get a problem on that, try
C( 52, 13 ) which is the number of possible
Indicate how you would fix the problem.
(It's not necessary to provide a second program,
just briefly write in English what you would do.)
|Send comments and mail to email@example.com.|