免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1645 | 回复: 3
打印 上一主题 下一主题

[C] 求解一道作业题(刚学c ,请大虾们指点)  关闭 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-12-04 15:10 |只看该作者 |倒序浏览
计算组合数的公式为:C(n,r)=n!/(r!(n-r)!).其中n,r为正整数且 n>=r .
以下程序的功能是求出组合数 C( 6 ,2 )的值,请补充完整之。
#include <stdio.h>
void main()
  {  long com( int n , int r ) ;
     printf(“com(6,2)=%ld\n”,com(6,2)) ;
  }
long com ( int n , int r )
   {       (1)       ;
      long x ;
      x = fact(n) /    (2)      ;
      return(x) ;
   }
long  fact ( int n)
{  if ( n==1)  return 1 ;
   else
       return   (3)   ;
}

论坛徽章:
1
天蝎座
日期:2013-08-25 10:27:22
2 [报告]
发表于 2008-12-04 15:15 |只看该作者
LZ标题很强悍。。

如果非作业的讨论,注意[code][/code]代码。

论坛徽章:
0
3 [报告]
发表于 2008-12-04 15:24 |只看该作者
我是新手啦,可以指点以下吗?  先说声谢谢

论坛徽章:
0
4 [报告]
发表于 2008-12-04 15:31 |只看该作者
#include <stdio.h>
int  main()
&nbsp;&nbsp;{  long com( int n , int r ) ;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf("com(6,2)=%ld\n",com(6,2)) ;
&nbsp;&nbsp;}
long com ( int n , int r )
&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;long  fact ( int n) ;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;long x ;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x = fact(n) /  (fact(r) * fact(n - r))      ;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return(x) ;
&nbsp;&nbsp;&nbsp;}
long  fact ( int n)
{  if ( n==1)  return 1 ;
&nbsp;&nbsp;&nbsp;else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return  n * fact(n -1)   ;
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP