Skip to content

Instantly share code, notes, and snippets.

@eyedean
Created October 15, 2013 20:15
Show Gist options
  • Save eyedean/6997941 to your computer and use it in GitHub Desktop.
Save eyedean/6997941 to your computer and use it in GitHub Desktop.
Write out all subsets of a given set.
#include <stdio.h>
#include <string.h>
int main()
{
int a[] = {1, 2, 3};
int n = sizeof(a) / sizeof (a[0]);
int i, j;
for (i=0; i<(1<<n); i++) {
for (j=0; j<n; j++)
if (i >> j & 1)
printf("%d ", a[j]);
printf("\n");
}
}
@eyedean
Copy link
Author

eyedean commented Oct 15, 2013

In response to http://qr.ae/Nc3yj

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment