PTA——组合数
PTA
7-48 求组合数
SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。1 #include<stdio.h> 2 double fact(int n); 3 4 int main() { 5 int m,n; 6 int c; 7 scanf("%d%d",&m,&n); 8 c=(int)(fact(n)/(fact(m)*fact(n-m))); 9 printf("result = %d",c); 10 } 11 12 double fact(int n) { 13 double p=1.0; 14 while(n) { 15 p *= n; 16 n--; 17 } 18 return p; 19 }
分析:
1、组合数一定是整数
2、阶乘函数应采用浮点数,若采用整型的话表示的数范围太小(int是16位,double是64位)

更多精彩