1.编写一个函数fun,它的功能是:根据以下公式求P的值,p=m!/n!(m-n)! , 结果由函数值带回。m与n为两个正整数,且要求m>n。
#include<iostream>
using namespace std;
int fun(unsigned int n,unsigned int m);
int main()
{
unsigned int a,b;
cin>>a>>b;
if(a>b)
{
cout<<"错误,请重新输入:";
cin>>a>>b;
}
cout<<fun(a,b)<<'\n';
return 0;
}
int fun(unsigned int n,unsigned int m)
{
int num(int x);
int p,c;
c=m-n;
p=num(m)/(num(n)*num(c));
return p;
}
int num(int x)
{
int s,i;
s=1;
for(i=1;i<=x;i++)
s=s*i;
return s;
}