Program 8
Program 8
Design and implement C/C++ Program to find a subset of a given set S = {sl , s2,.....,sn} of n positive
integers whose sum is equal to a given positive integer d.
#include<stdio.h>
void main()
{
int n, sum=0, i;
printf("\n Enter the size of the set:");
scanf("%d",&n);
printf("Enter the set in increasing order:\n");
for(i=1; i<=n; i++)
scanf("%d",&s[i]);
printf("Enter the value of d:\n");
scanf("%d",&d);
if(sum<d || s[1]>d)
printf("No subset possible");
else
sumofsub(0,1,sum);
}
if((m+s[k])==d)
{
printf("Subset:");
for(i=1; i<=k; i++)
if(x[i]==1)
printf("\t%d",s[i]);
printf("\n");
}
else
if(m+ s[k]+ s[k+1]<=d)
sumofsub(m+s[k], k+1, r-s[k]);