- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubsetSumProblem.cpp
More file actions
Latest commit
39 lines (39 loc) · 565 Bytes
/
Copy pathSubsetSumProblem.cpp
File metadata and controls
39 lines (39 loc) · 565 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include<iostream>
usingnamespacestd;
boolSum(int arr[],int n,int sum)
{
if(sum==0)
{
return1;
}
if(sum!=0 && n==0)
{
return0;
}
if(arr[n-1]>sum)
{
returnSum(arr,n-1,sum);
}
return (Sum(arr,n-1,sum)||Sum(arr,n-1,sum-arr[n-1]));
}
intmain()
{
int arr[100],sum=15;
int n;
cout<<"Enter the size of array : \n";
cin>>n;
cout<<"Enter the array element : \n";
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
if(Sum(arr,n,sum)==1)
{
cout<<"Sum found";
}
else
{
cout<<"Sum not found";
}
return0;
}