solutions to print C(n,r)

#include<stdio.h>
int zuheC( int n,int r );
int C( int n,int r );
int main(void)
{
    int n,r;
    printf( "Enter the numbers: n and r" );
    scanf( "%d%d",&n,&r );
    zuheC( n,r );
    return 0;
}
int zuheC( int n,int r )
{  
    int array[n];
    int i,j,k,maxnum,times;
    for( i = 0;i != r;i++ )  {
        array[i] = i + 1;
        printf( "%d",array[i] );
       }
    printf( " \n");
    times = C( n,r );
    for( i = 1;i != times;i++ )
      {
        j = r - 1;
        maxnum = n;
        while( array[j] == maxnum )
          {
            j--;maxnum--;
          }
        array[j]++;
        for( k = j + 1;k < r;k++ )
            array[k] = array[k-1] +1;
        for( k = 0;k < r;k++ )
            printf( "%d",array[k] );
        printf( "\n" );
      }
}
int C( int n,int r )
{
    int temp = n - r + 1;
    int sum = 1;
    while( temp < n + 1 )
        sum = sum * temp++;
    temp = 1;
    while( temp < r + 1 )
        sum = sum / temp++;
    return sum;
}


你可能感兴趣的:(c)