Competitive C/C++ Programming for Beginners
Pages
Home
Algorithms
Books
Wednesday, September 18, 2013
Printing all possible subsets using Bit Mask
#include<stdio.h>
void PrintAllSubset(int n)
{
int mask,pos,i,j,no = 1<<n;
for(i=1;i<no;i++)
{
for(j=0;j<n;j++)
if((i&(1<<j)) > 0)
printf("%d ",j+1);
printf("\n");
}
}
int main()
{
int n;
while(scanf("%d",&n) == 1)
{
PrintAllSubset(n);
}
return 0;
}
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment