CodeBarn
8/5/2018 - 7:19 AM

All Subsets

Print all possible subsets for set of integers from 0..N-1

  int N = 10;
  int A[N];
  iota(A, A + N, 0);
  for (int i = 0; i < (1 << N); i++) {
    for (int j = 0; j < N; j++)
      if (i & (1 << j))
        cout << A[j] << " ";
    cout << "\n";
  }