y is it shwoing eror
Move all x at end
#include
using namespace std;
int key;
int subs(int *arr, int *out , int i, int j,int n){
if( i== n ){
int sum=0,chk=0;
if(out[0]>1)
chk=1;
for(int k=0; k<j;k++){
// cout<<out[k]<<" ";
sum=sum+out[k];
}
cout<< sum<<endl;
if(sum==0 && chk == 1)
return 1;
else
return 0;
}
out[j]= arr[i];
int p= subs(arr ,out , i+1,j+1,n);
int p1=subs(arr, out , i+1,j,n);
return (p^p1);
}
int main() {
int t,n;
cin>>t;
while(t–){
cin>>n;
int arr[n],out[n];
for(int i=0 ;i <n ;i++){
cin>>arr[i];
}
int s=subs(arr,out,0,0,n);
if(s==1)
cout<<“yes”;
else cout<<“no”;
}
return 0;
}
this is the problem to find out that is there any subset which has a sum = to 0 ,
my code is giving no even when it has sum as a zero.
can u please tell whats the mikstake …
check for 1 2 -3 this has a sum zero but it is showing no
instead of p^p1 i even wrote p || p1 . it was still not working
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.
my question is something else acutally