Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create subset_sum.c #1562

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Bit Manipulation/Subset sum greater than N/subset_sum.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
int subsetsum(int *set,int set_size,int value)
{
int count=0,x,k;
for(x=0;x<pow(2,set_size);x++)
{
int sum=0;
for(k=0;k<set_size;k++)
{
if( (x&(1<<k))!=0)
sum+=set[k];
}
if(sum>=value)
count++;
}
return count;

}

int main()
{
int arr[]={1,2,3};
int n=5;
int answer=subsetsum(&arr,3,n);
printf("%d",answer);
return 0;
}