#include
int bit_count(unsigned int n)
{
int count;
for(count = 0; n; n=n &(n - 1))
{
count++;
}
return count;
}
int main()
{ int k;
int num;
printf("輸入一個數(shù):");
scanf("%d",&num);
k=bit_count(num);
printf("1的個數(shù)為%d\n",k);
return 0;
}
#include
int bit_count(unsigned int n)
{
int count;
for(count = 0; n; n=n &(n - 1))
{
count++;
}
return count;
}
int main()
{ int k;
int num;
printf("輸入一個數(shù):");
scanf("%d",&num);
k=bit_count(num);
printf("1的個數(shù)為%d\n",k);
return 0;
}