# include # include using namespace std; int main ( ) // // POKER_HANDS tries to compute the number of possible hands in // poker. The correct answer is 52-choose-5 or 52!/(47!*5!) and // the program computes exactly this number but ends up failing. // // You are invited to think about what could have gone wrong. // { int choose ( int n, int k ); int n, k, hands; n = 52; k = 5; hands = choose ( n, k ); cout << "From a deck of " << n << " cards," << " we choose " << k << " cards to form a hand.\n"; cout << "Assuming the order of the 5 cards doesn't matter,\n"; cout << "there are " << hands << " different hands we can draw.\n"; return 0; } int choose ( int n, int k ) { int factorial ( int n ); int value; value = factorial ( n ) / factorial ( k ) / factorial ( n - k ); return value; } int factorial ( int n ) { int i; int value; value = 1; for ( i = 1; i <= n; i++ ) { value = value * i; } return value; }