home *** CD-ROM | disk | FTP | other *** search
- // C++ program which uses a recursive function
-
- #include <iostream.h>
-
- const int MIN = 4;
- const int MAX = 30;
-
- double factorial(int i)
- {
- if (i > 1)
- return double(i) * factorial(i - 1);
- else
- return 1;
- }
-
- double permutation(int m, int n)
- {
- return factorial(m) / factorial(m - n);
- }
-
- double combination(int m, int n)
- {
- return permutation(m, n) / factorial(n);
- }
-
- main()
- {
- int m, n;
-
- do {
- cout << "Enter an integer between "
- << MIN << " and " << MAX << " : ";
- cin >> m;
- } while (m < MIN || m > MAX);
-
- do {
- cout << "Enter an integer between "
- << MIN << " and " << m << " : ";
- cin >> n;
- } while (n < MIN || n > m);
-
- cout << "Permutations(" << m << ", " << n
- << ") = " << permutation(m, n) << "\n";
- cout << "Combinations(" << m << ", " << n
- << ") = " << combination(m, n) << "\n";
-
- return 0;
- }
-