forked from Abhijeet5665/c-programs-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubsets.c
53 lines (34 loc) · 739 Bytes
/
subsets.c
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
50
51
#include <stdio.h>
int A[5]= {0};
char B[5]={'V','A','B','C','D'};
void print2(int A[], int N){
for (int i =1; i <=N; i++){
if(A[i] ==1){
printf("%c ",B[i]);
}
}
printf("\n");
}
void print(int A[], int N){
for (int i =1; i <=N; i++){
printf("%d ",A[i]);
}
printf("\n");
}
void combination(int A[], int k, int N) {
//printf("k=%d\n",k);
if (k==N) {
A[k]=0;
print2(A,N);
A[k]=1;
print2(A,N);
return;
}
A[k]=0;
combination(A,k+1,N);
A[k]=1;
combination(A,k+1,N);
}
int main(){
combination(A,1,4);
}