forked from Abhijeet5665/c-programs-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubsets1.c
More file actions
57 lines (41 loc) · 652 Bytes
/
subsets1.c
File metadata and controls
57 lines (41 loc) · 652 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
37
38
39
40
41
42
43
44
45
46
47
48
49
#include<stdio.h>
void print(int a[],int n,int b[]){
int sum=0,i;
for(i=0;i<=n;i++)
{
if(a[i]==1){
printf("%d ",b[i]);
sum++;
}
}
if(sum==0)
printf("empty");
printf("\n");
}
void combination(int a[],int k,int n,int b[]){
if(k==n)
{
a[k]=0;
print(a,n,b);
a[k]=1;
print(a,n,b);
return;
}
a[k]=0;
combination(a,k+1,n,b);
a[k]=1;
combination(a,k+1,n,b);
}
void main(){
printf("eneetr the array size\n");
int n;
scanf("%d",&n);
int b[n];
int a[n],i;
//array contains all the elemnts of array for which we want to find the all subsets
for(i=0;i<n;i++){
scanf("%d",&b[i]);
a[i]=0;//temporary binary digits
}
combination(a,0,n-1,b);//explain
}