使用 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 红包祝福语简短10字
18 周六早晨祝福语简短