[FZH] 一个C语言题目
宏羽杜
dongfengweixiao at gmail.com
Wed May 18 00:47:14 UTC 2011
简单的看了下,似乎是有问题的
在 2011年5月18日 上午12:45,David Young <dhyang555 at gmail.com>写道:
> 在 2011年5月17日 下午7:37,宏羽杜 <dongfengweixiao at gmail.com>写道:
>
> > 这个题目的算法很单纯,但是结果很蛋疼。
> >
> > 一共出了三个问题:
> 当然最大的问题是算组合数时的公式写错了,排错时才发现,第二个就是循环应该从0开始,第三个问题是,==错写成=.
> Version 2.0版如下:
> #include <stdio.h>
> int fab(int number)
> {
> if(number>0)
> return fab(number-1)*number;
> else if(number==0)
> return 1;
> return -1;
> }
> int comb(int number,int count)
> {
> int a,b,c;
> a=fab(number);
> b=fab(count);
> c=fab(number-count);
> if((a<0)||(b<0)||(c<0))
> return 0;
> else
> return a/b/c;
> }
>
> int main()
> {
> int sum=0,count,number;
> scanf("%d",&number);
> number--;
> for(count=0;count<=number;++count)
> {
> sum+=comb(number,count);
> }
>
> printf("the result is:%-d\n",sum);
> return 0;
> }
> _______________________________________________
> Chinese mailing list
> Chinese at lists.fedoraproject.org
> https://admin.fedoraproject.org/mailman/listinfo/chinese
>
--
我的QQ:275471710
我的推特:dongfengweixiao
我的E_mail:dongfengweixiao at gmail.com
More information about the Chinese
mailing list