double
lnchoose(int
n,
int
m)
{
if
(m
>
n)
{
return
0;
}
if
(m
<
n/2.0)
{
m
=
n-m;
}
double
s1
=
0;
for
(int
i=m+1;
i<=n;
i++)
{
s1
+=
log((double)i);
}
double
s2
=
0;
int
ub
=
n-m;
for
(int
i=2;
i<=ub;
i++)
{
s2
+=
log((double)i);
}
return
s1-s2;
}
double
choose(int
n,
int
m)
{
if
(m
>
n)
{
return
0;
}
return
exp(lnchoose(n,
m));
}
用之前调用math.h头文件,用的话直接把值赋给choose()这个函数即可,直接调用上面的函数,返回一个double数值,可追问