使用 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
热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短