Cod sursa(job #770682)
Utilizator | IT Zilla ibicec | Data | 23 iulie 2012 17:06:37 |
---|---|---|---|
Problema | Submultimi | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.49 kb |
#include <stdio.h>
#include <math.h>
int main()
{
// freopen("submultimi.in", "rt", stdin);
// freopen("submultimi.out", "wt", stdout);
short n;
scanf("%hu", &n);
unsigned short subs = pow(2,n)-1; // number of subsets
unsigned short cur_sub = 1; // current subset
for ( int i=0; i<subs; i++ ) { // iterating through all subsets
for ( int j=0; j<n; j++ ) {
if ( cur_sub & ( 1 << j ) ) {
printf("%hu ", j+1);
}
}
printf("\n");
cur_sub++;
}
}