Answers for "How to generate all the possible subsets of a set ?"

C++
0

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:\n";
 for(int i=0;i<(1<<n);i++){
     for(int j=0;j<n;j++){
        if(i&(1<<j)){
             cout<<v[j]<<" ";
        }
     }
     cout<<'\n';
 }

return 0;
}
Posted by: Guest on April-11-2022

Code answers related to "How to generate all the possible subsets of a set ?"

Browse Popular Code Answers by Language