【15分】F. 求组合数(函数)
题目描述
编写一个函数,m和n是参数,按以下公式求组合数的值,假设m,n都是正整数,且m>=n。
主函数负责输入m和n的值,并调用函数求出组合数的值,并输出
输入
测试数据的组数 t
第一组m,n
第二组m,n
…
输出
第一组组合数的值
第二组组合数的值
…
输入样例1
3
8 5
6 3
10 8
输出样例1
56
20
45
代码
#include <iostream>
using namespace std;
int Factorial(int n)
{
if(!n) return 1;
return n * Factorial(n - 1);
}
int count(int m,int n)
{
return Factorial(m) / Factorial(n) / Factorial(m - n);
}
int main()
{
int num;
cin >> num;
while(num --)
{
int m,n;
cin >> m >> n;
cout << count(m,n) << endl;
}
}