文章
34
粉丝
109
获赞
7
访问
19.3k
#include <stdio.h>
int main()
{
int n;
int num[32] = {0};
while (scanf("%d", &n) != EOF)
{
int index = 0;
while (n > 0)
{
num[index++] = n % 2;
n = n / 2;
}
int count0 = 0, count1 = 0;
for (int i = 0; i < 32; i++)
{
if (num[i] == 0)
{
count0++;
}
else
{
count1++;
}
}
printf("count0=%d count1=%d\n", count0, count1);
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发