#include <bitset>
#include <iostream>
#include <math.h>
#include <vector>

int main() {
using namespace std;
int arr[] = {1,2,3,4};
int k = 2;
int n = sizeof(arr)/sizeof(int);
vector<int> v(arr, arr+n);
int l = pow(2.0, n);
for (int i = 0; i < l; ++i) {
bitset<32> b(i);
if (b.count() != k)
continue;
for (int j = 0; j < n; ++j) {
if (b[j])
cout << arr[j] << " ";
}
cout << endl;
}
return 0;
}

On Tue, Jul 26, 2011 at 11:59 AM, sumit <sumitispar...@gmail.com> wrote:

> Given an array of size n, print all the possible subset of array of
> size k.
> eg:-
> input:
> a[]={1,2,3,4}, k = 2
> output:
> 1,2
> 1,3
> 1,4
> 2,3
> 2,4
> 3,4
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to