1. 程式人生 > >C語言求組合數C(n,m)

C語言求組合數C(n,m)

#include<stdio.h>
int main()
{
int n,m;
double n1,m1,o1;
double fact(int n);
printf("Enter n and m(m<=n):\n");
scanf("%d%d",&n,&m);
n1=fact(n);
m1=fact(m);
o1=fact(n-m);
printf("%0.1f\n",n1/(m1*o1));
}
double fact(int n)//求階乘
{
int i;
double sum;
sum=1;
for(i=1;i<=n;i++)
{
sum=sum*i;
}
return sum;
}