#include<bits/stdc++.h>
using namespace std;
int main()
{
int n, i;
cout << "Enter A Number :: ";
cin >> n;
int a[n], sum = 0, f = 1;
cout << "\nEnter Array Element :: ";
for(i=0; i<n; i++)
cin >> a[i];
unordered_set<int>s;
for(i=0; i<n; i++)
{
sum += a[i];
if(sum == 0 || s.find(sum) != s.end())
{
f = 0;
cout << "\nSubset sum is 0 Found." << "\n";
break;
}
s.insert(sum);
}
if(f == 1)
cout << "\nSubset sum is 0 Not Found." << "\n";
return 0;
}
Comments
Post a Comment