#include<stdio.h>
int fanc(unsigned int n);
int main(void)
{
int n,k;
scanf("%d",&n);
k=fanc(n);
printf("二进制中1的个数=%d\n",k);
return 0;
}
int fanc(unsigned int n)
{
int con=0;
while(n>0)
{
n&=n-1;
con++;
}
return con;
}
#include<stdio.h>
int fanc(unsigned int n);
int main(void)
{
int n,k;
scanf("%d",&n);
k=fanc(n);
printf("二进制中1的个数=%d\n",k);
return 0;
}
int fanc(unsigned int n)
{
int con=0;
while(n>0)
{
n&=n-1;
con++;
}
return con;
}
转载于:https://www.cnblogs.com/lipiao/p/4110853.html