About Me

Thursday, February 9, 2012

In how many ways may we pick a subset from 1, 2, 3, 4, … n so that no two successive numbers are picked?


2 comments:

  1. this will work :-

    please let me know if you find any bug.

    void count(int arr[],int len,int inc,int i,int k)
    {
    int j;
    static int result[100];


    if(i>=len)
    {
    return;

    }
    while(i<len)
    {
    result[k]=arr[i];
    printf("\n");
    for(j=0;j<k+1;j++)
    {
    printf("%d ",result[j]);
    }
    count(arr,len,inc,i+inc,k+1);

    if(k!=0)
    {
    inc++;
    }
    i++;
    }


    }

    call :-
    count(arr,arrlen,2,0,0);

    ReplyDelete
  2. i found one bug :-

    remove

    if(k!=0)
    {
    inc++;
    }

    from above code and it will work fine, i was thinking too much . actually i++ will do the job instead of doing inc++;

    ReplyDelete

Hi thanks , we will get back to you shortly !!!