/*(2‐1)组合数求解公式为
n m!
Cm = --------
n!(m-n)!
编程序输入m,n,输出组合数,要求用自定义
函数实现求阶乘。
* 算法说明:
* 1.定义阶乘函数时,首先定义一个变量,用来储存数据并赋初值为1;
* 2.对一些有规律的数进行运算,用循环完成
* 3.对数据运算的简单处理
*/
#include <iostream>
using namespace std;
long fac(int n) //求n 的阶乘
{
int st_n = 1;
while (n > 0)
{
st_n = n*st_n;
--n;
}
return st_n;
}
int main()
{
int m, n, C_mn;
cout <<"请输入要求组合数m,n的值:"<< endl;
cin >> m >> n;
C_mn = fac(m)/(fac(n) * fac(m-n));
cout << C_mn << endl;
system("PAUSE");
return 0;
}
