编写一个函数,m和n是参数,按以下公式求组合数的值,假设m,n都是正整数,且m>=n。
主函数负责输入m和n的值,并调用函数求出组合数的值,并输出
测试数据的组数 t
第一组m,n
第二组m,n
..........
第一组组合数的值
第二组组合数的值
..........
3 8 5 6 3 10 8
56 20 45
#include<iostream>
using namespace std;
long long fact(int n)
{
int i=1,fact=1;
for(i=1;i<=n;i++)
fact=fact*i;
return fact;
}
int main()
{
int t;
cin>>t;
while(t--)
{
int m,n;
cin>>m>>n;
cout<<fact(m)/(fact(n)*fact(m-n))<<endl;
}
}
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有