Skip to content

Instantly share code, notes, and snippets.

@tywong
Created June 8, 2016 07:25
Show Gist options
  • Save tywong/505ac6dce930b79a63ec0546fa855f98 to your computer and use it in GitHub Desktop.
Save tywong/505ac6dce930b79a63ec0546fa855f98 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
void print_result(int result[], int len) {
int i;
if(len == 0)
printf("NOTHING\n");
else {
for(i = 0; i < len; i++)
printf("%d ", result[i]);
printf("\n");
}
}
void power_set(int choice, int pos, int remain, int result[]) {
if(remain == 0) {
print_result(result, pos);
return ;
}
result[pos] = choice;
power_set(choice+1, pos+1, remain-1, result);
power_set(choice+1, pos, remain-1, result);
}
int main(void) {
int N;
int result[10];
scanf("%d", &N);
power_set(1, 0, N, result);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment