Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <cstring>
- using namespace std;
- void subset(int* set) {
- int n = 3; // for example three size of data
- cout << "-" << endl;;
- for (int i = 1; i < (1 << n); i++) {
- for (int j = 0; j < n; j++) {
- if (i & (1 << j))
- cout << set[j] << ",";
- }
- cout << endl;
- }
- }
- int main() {
- int set[3] = { 1,2,3 };
- subset(set);
- return 0;
- }
- #include <iostream>
- #include <math.h>
- using namespace std;
- void printPowerSet(char *set, int set_size)
- {
- /*set_size of power set of a set with set_size
- n is (2**n -1)*/
- unsigned int pow_set_size = pow(2, set_size);
- int counter, j;
- /*Run from counter 000..0 to 111..1*/
- for(counter = 0; counter < pow_set_size; counter++)
- {
- for(j = 0; j < set_size; j++)
- {
- /* Check if jth bit in the counter is set
- If set then print jth element from set */
- if(counter & (1 << j))
- cout << set[j];
- }
- cout << endl;
- }
- }
- /*Driver code*/
- int main()
- {
- char set[] = {'a','b','c'};
- printPowerSet(set, 3);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement