标签:return count scan 统计 for scanf i++ turn code
//求一个整数在二进制中1的个数
int main()
{
int num = 0;
int count = 0;
scanf("%d", &num);
////统计num的补码中有几个1
//while (num)
//{
// if (num% 2== 1)
// count++;
// num = num / 2;
//}
int i = 0;
for (i = 0;i < 32;i++)
{
if(1==((num>>i)&1))
count++;
}
printf("%d\n", count);
return 0;
}
标签:return count scan 统计 for scanf i++ turn code
原文地址:https://blog.51cto.com/15057883/2568191