[FZH] 一个C语言题目

David Young dhyang555 at gmail.com
Tue May 17 06:37:50 UTC 2011


这是组合数学中的问题。用纯C写一下。
#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)
      {
           if((count<=number)&&(number<=20)&&(number>0))
               return (fab(number)/fab(number-count));
           return -1;
      }

 int main()
{
    int sum=0,count,number;
    scanf("%d",&number);
    for(count=1;count<number;++count)
        {

           sum+=comb(number,count);

        }

     printf("the result is:%-d\n",sum);
     return 0;
}


More information about the Chinese mailing list