Unformatted text preview: } int Factorial(int x) // PRE: x >= 0 // POST: FCTVAL == x!, i.e. the factorial of x { int result = 1; // factorial of x; starts at 1 // as we'll multiply by it and // as 0! = 1 for(int i = 1; i <= x; i++) // multiply result by all numbers { // b/w 1 and x to find factorial result = result * i; } return result; } int NumCombinations(int n, int r) // PRE: n > 0 && r >= 0 && r <= n // POST: FCTVAL == number of ways to choose r objects chosen from n // (without regard to order) { return NumPermutations(n, r)/Factorial(r); } int main() { cout << "P(5, 2) = " << NumPermutations(5, 2) << endl; cout << "5 choose 2 = " << NumCombinations(5, 2) << endl; return 0; }...
View
Full Document
 Fall '10
 Doug Hogan

Click to edit the document details