I am working on an assignment and i made a function to get the power set and it worked but if the set like this:
{1,2,3}
it print out this :
{{},{1,},{2,},{1,2,},{3},{1,3},{2,3},{1,2,3}}
and i can't remove these commas to become like that:
{{},{1},{2},{1,2},{3},{1,3},{2,3},{1,2,3}}
Source code for this function:
void power_set(int set1[], int set1_length) {
int power = pow(2,set1_length);
cout << "{";
for (int i = 0; i < power; i++) {
cout << "{";
for (int j = 0; j < set1_length; j++ ) {
if(i & (1<<j)) {
cout << set1[j];
if (j < set1_length - 1) cout << ",";
}
}
cout << "}";
if (i != power - 1)cout << ",";
}
cout << "}";
}