Created
October 15, 2013 20:15
-
-
Save eyedean/6997941 to your computer and use it in GitHub Desktop.
Write out all subsets of a given set.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In response to http://qr.ae/Nc3yj