I hope this solution will find the all the subsets from set S . The sum of
elements in subset is equivalent to certain no. k.

fun(int a[],int k){
                int i,j;
                int k1;
                for(i=0;i<10;i++){
                        k1=a[i];
                        j=i+1;

                        while(j<10){
//if we have 10 elements in set S;
                                k1=k1+a[j];
                                if(k>k1){
                                        j++;
                                }else if(k==k1){
                                        printf("True\t");
                                        while(k1!=0){
                                                printf("%d\t",a[j]);
                                                k1=k1-a[j];
                                                j--;
                                        }
                                        printf("\n");
                                }else if(k<k1)  {
                                        break;
                                }
                        }
                }
        }


---
Regards
Peeyush Bishnoi


On 4/30/07, Cool_Happy <[EMAIL PROTECTED]> wrote:
>
>
> Suppose u r given a positive number N.
> How will we find a set of distinct positive numbers having sum equal
> to N.
> There could be multiple such sets so what is the algo to find all
> those sets.
>
> TIA
> Negi
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Reply via email to