码迷,mamicode.com
首页 > 其他好文 > 详细

PTA——组合数

时间:2019-04-23 21:05:38      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:clu   int   col   ble   pre   组合数   整型   ret   style   

PTA

7-48 求组合数

 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位)

 

PTA——组合数

标签:clu   int   col   ble   pre   组合数   整型   ret   style   

原文地址:https://www.cnblogs.com/cxc1357/p/10758472.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!