-
Notifications
You must be signed in to change notification settings - Fork 121
/
array.cpp
33 lines (30 loc) · 852 Bytes
/
array.cpp
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
#include <iostream>
using namespace std;
void printSubsetsOfArray(int input[],int size, int output[],int outputSize){
if(size == 0){
for(int i=0;i<outputSize;i++){
cout<<output[i]<<" ";
}
cout<<endl;
return;
}
printSubsetsOfArray(input+1,size-1,output,outputSize);
//assuming current elemnet is included in array
int newoutput[20] = {};
for(int i=0;i<outputSize;i++){
newoutput[i] = output[i];
}
newoutput[outputSize] = input[0];
printSubsetsOfArray(input+1,size-1,newoutput,outputSize+1);
}
void printSubsetsOfArray(int input[], int size) {
int ans[20] = {};
printSubsetsOfArray(input,size,ans,0);
}
int main() {
int input[1000],length;
cin >> length;
for(int i=0; i < length; i++)
cin >> input[i];
printSubsetsOfArray(input, length);
}