forked from Abhijeet5665/c-programs-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumbersubset.c
More file actions
68 lines (48 loc) · 997 Bytes
/
numbersubset.c
File metadata and controls
68 lines (48 loc) · 997 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <stdio.h>
//int A[5]= {0};
void print2(int A[], int N,int B[]){
int sum=0;
for (int i =0; i <=N; i++){
if(A[i] ==1){
printf("%d ",B[i]);
sum++;
}
}
if(sum==0)
printf("empty");
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,int B[]) {
//printf("k=%d\n",k);
if (k==N) {
A[k]=0;
print2(A,N,B);
A[k]=1;
print2(A,N,B);
return;
}
A[k]=0;
combination(A,k+1,N,B);
A[k]=1;
combination(A,k+1,N,B);
}
int main(){
int n;
printf("eneter the array size\n");
scanf("%d",&n);
int B[n],i;
int A[n];
printf("eneter the array elemnts\n");
for(i=0;i<n;i++){
scanf("%d",&B[i]);
A[i]=0;
}
printf("-----------------------------------\n");
combination(A,0,n-1,B);
}