Friday, 6 April 2012

Approach #1 for generate the sequence

 #include<stdio.h>
#include<math.h>
main()
{
int n;
long long int num,i,x,j;
long int cnt=0;
printf("\n enter the number of bits :");
scanf("%d",&n);
num=pow(2,n);
printf("\n %lld",num);
for (i=0;i<num;i++)
{
    for (j=0;j<num;j++)
    {
    x=j;
    cnt=0;

    while (x)
        {
        if (x&1)
        cnt++;
        x=x>>1;
        }
    if (cnt==i)
        printf("\n %lld : %ld",j,cnt);
    }
}   
return 1;
}

No comments:

Post a Comment