forked from v100901/hackoctoberfest2020__
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubset_Of_Array.cpp
More file actions
36 lines (34 loc) · 795 Bytes
/
Subset_Of_Array.cpp
File metadata and controls
36 lines (34 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//SOLVED USING BINARY METHOD...
#include<iostream>
#include<bits/stdc++.h>
#define ull unsigned long long int
using namespace std;
int dectobinary(int i){
if(i==0)
return 0;
else
return i%2+10*(dectobinary(i/2));
}
int main(){
int n,count=0,k=0,rem;
cin>>n;
int *arr=new int[n];
for(int i=0;i<n;i++)
cin>>arr[i];
for(int i=0;i<pow(2,n);i++){
int a=dectobinary(i);
int div=pow(10,n-1)+1;//g++ compiler return 10^2 as 99
for(int j=0;j<n;j++)
{
int q=a/div;
int r=a%div;
if(q==0)
cout<<"";
else
cout<<arr[j]<<" ";
a=r;
div=div/10;
}
cout<<endl;
}
}