-
Notifications
You must be signed in to change notification settings - Fork 364
/
Power_Set.c
34 lines (28 loc) · 819 Bytes
/
Power_Set.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
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void generatePowerSet(int originalSet[], int numElements) {
int numSubsets = pow(2, numElements);
for (int i = 0; i < numSubsets; i++) {
printf("{ ");
for (int j = 0; j < numElements; j++) {
if ((i & (1 << j)) != 0) {
printf("%d ", originalSet[j]);
}
}
printf("}\n");
}
}
int main() {
int numElements;
printf("Enter the number of elements in the original set: ");
scanf("%d", &numElements);
int originalSet[numElements];
printf("Enter the elements of the original set: ");
for (int i = 0; i < numElements; i++) {
scanf("%d", &originalSet[i]);
}
printf("Power Set:\n");
generatePowerSet(originalSet, numElements);
return 0;
}