Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

How to generate all the possible subsets of a set ?

#include<bits/stdc++.h>
using namespace std;

int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);

  int n;
  cin>>n;
 vector<char>v(n);
 for(int i=0;i<n;i++){
     cin>>v[i];
 }
cout<<"All Possible subset:
";
 for(int i=0;i<(1<<n);i++){
     for(int j=0;j<n;j++){
        if(i&(1<<j)){
             cout<<v[j]<<" ";
        }
     }
     cout<<'
';
 }

return 0;
}
 
PREVIOUS NEXT
Tagged: #How #generate #subsets #set
ADD COMMENT
Topic
Name
7+2 =