题解 | #查找输入整数二进制中1的个数#
查找输入整数二进制中1的个数
http://www.nowcoder.com/practice/1b46eb4cf3fa49b9965ac3c2c1caf5ad
#include<stdio.h>
#include<math.h>
int main()
{
int n;
while(scanf("%d", &n) != EOF)
{
int cnt = 0;
int i = 0;
while(pow(2, i) < n)
{
if((n>>i) & 1 == 1)
cnt++;
i++;
}
printf("%d\n", cnt);
}
return 0;
}
