题解 | #查找输入整数二进制中1的个数#
查找输入整数二进制中1的个数
https://www.nowcoder.com/practice/1b46eb4cf3fa49b9965ac3c2c1caf5ad
#include <stdio.h>
int main() {
int a, b;
b=0;
while(scanf("%d",&a)!=EOF)
{
b=0;
if(a==0)
printf("0");
while(a>0)
{
if(a%2==1)
b++;
a=a/2;
}
printf("%d\n",b);
}
return 0;
}
查看6道真题和解析