1 #include <stdio.h>
2
3 int main(int argc, char **argv)
4 {
5 int x;
6 printf("请输入想计算的整数:");
7 scanf("%d", &x);
8
9 printf("%d中 1 的个数为%d\n", x, Count(x));
10
11
12 return 0;
13 }
14
15 int Count(int x)
16 {
17 int count;
18
19 while(x)
20 {
21 count++;
22 x = x & (x-1);
23 }
24
25 return count;
26 }