编写函数fun,它的功能是:根据以下公式求p的值,结果由函数值带回。m与n为两个正整数且要求m>n。

日期:2012-01-28 15:06:16 人气:1

编写函数fun,它的功能是:根据以下公式求p的值,结果由函数值带回。m与n为两个正整数且要求m>n。

/* 是p=m!/n!(m-n)! */ float fun(int m,int n) { float p,t=1.0; int i; for (i=1;i<=m;i++) t=t*i; p=t; for(t=1.0,i=1;i<=n;i++) t=t*i; p=p/t; for(t=1.0,i=1;i<=m-n;i++) t=t*i; p=p/t; return p; }
    A+
热门评论