Arrays

Hi there,

I have been trying to create a program which prints the elements of an array in combinations.

Is there any way on how to go with that?

Thanks and regards
What combinations? All subsets?
yes. exactly. all subsets.
Given a set with 'n' elements all possible subsets. In case that it helps, below what I ve done so far

#include<iostream>
using namespace std;

void Combs(int B[], int n, int y)
{
int D[4];
for (int j = 0; j <= n; j++)
{
D[0] = B[j];


cout << "\n";
for (int i = 0; i < y; i++)

{
cout << B[i];
}

// Combs(D, n, y+1);
y++;


}
}

int main() {
int y = 0;
int n;
cout << "Enter the n\n";
cin >> n;
int *B = new int[n]; for (int i = 0; i <n; i++) B[i] = i;
cout << "All possible subsets are :\n";
Combs(B, n, y);
cout << endl;
system("pause");
}
It's a rather common problem, you can also do it in an iterative way:
http://www.geeksforgeeks.org/power-set/
Just a comment: "Combinations" means something entirely different than "all possible subsets". As @GoldenLizard's link suggests, you're looking for the "power set".
Thank you both for the replies.
Yeah, you re right. In fact I am looking for the power set.
However, the one suggested is not exactly what i m looking for.
What i need to do is to print the subsets based on the index of the array recursively.
Topic archived. No new replies allowed.