题解 | #求int型正整数在内存中存储时1的个数#
求int型正整数在内存中存储时1的个数
http://www.nowcoder.com/practice/440f16e490a0404786865e99c6ad91c9
int main(void) {
int n;
int m = 0;
int count = 0;
scanf("%d", &n);
//每次左移一位,左移前的值与左移后的值取余,如果=0,即左移掉的值不是1
while(n > 0) {
m = n;
n = n >> 1;
if(n != 0 && m%n != 0 || n == 0 || m == 3 && n == 1) {
count++;
}
}
printf("%d", count);
}