home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C Programming Starter Kit 2.0
/
SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso
/
tybc4
/
advfun6.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1993-03-31
|
1KB
|
49 lines
// 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;
}