使用 nCr 的递归关系计算组合的 C++ 程序
这是一个C++程序,用于使用nCr的递归关系计算组合。
算法
Begin
function CalCombination():
Arguments: n, r.
Body of the function:
Calculate combination by using
the formula: n! / (r! * (n-r)!.
End示例
#includeusing namespace std; float CalCombination(float n, float r) { int i; if(r > 0) return (n/r)*CalCombination(n-1,r-1); else return 1; } int main() { float n, r; int res; cout<<"输入n的值: "; cin>>n; cout<<"输入r的值: "; cin>>r; res = CalCombination(n,r); cout<<"\nThe number of possible combinations are: nCr = "< 输出结果 输入n的值: 7 输入r的值: 6 The number of possible combinations are: nCr = 2
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下