Pagini recente » Cod sursa (job #322192) | Cod sursa (job #1708801) | Cod sursa (job #1072971) | Cod sursa (job #1434848) | Cod sursa (job #770683)
Cod sursa(job #770683)
#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++;
}
}