1、写一个函数输出a的二进制(补码)中1的个数。
int count_(int a)
{
int count = 0;
for (int i = 0; i < 32; i++)
{
if (((a >> i) & 1) == 1)
count++;
}
return count;
}
int main()
{
int count = 0;
int a = 0;
scanf("%d", &a);
count=count_(a);
printf("count = %d\n", count);
}
标签:count,return,--,scanf,练习,++,C语言,int
From: https://blog.51cto.com/u_16071993/6232518