Created
June 8, 2016 07:25
-
-
Save tywong/505ac6dce930b79a63ec0546fa855f98 to your computer and use it in GitHub Desktop.
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> | |
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