i am not able to get the correct output and i ve checked the code many times couldn’t find any logical or syntax error.
please help,
code is below-
#include
using namespace std;
bool sum(int *arr,int n){
int s=0;
for(int i=0;i<n;i++){
s+=arr[i];
}
if(s==0){
return true;
}else{
return false;
}
}
bool sub(int *arr,int i,int *input){
int j=0;
int p=0;
while(i>0){
if(i&1){
input[p++]=arr[j];
}
j++;
i>>1;
}
if(p>0)
return sum(input,p);
else
return false;
}
bool check(int *arr,int n){
int input[n];
bool x=false;
for(int i=0;i<(1<<n);i++){
x=x or sub(arr,i,input);
}
return x;
}
int main() {
int t;
int n;
int arr[n];
cin>>t;
while(t–){
cin>>n;
for(int i=0;i<n;i++){
cin>>arr[i];
}
bool p=check(arr,n);
if(p==true){
cout<<“Yes”;
}
else
{
cout<<“No”;
}
}
return 0;
}