#include<stdio.h>
int main()
{
int num;
int s=0,ys=0,count=0;
printf("请输入一个数字:");
scanf("%d",&num);
for(s=num;s>=1;)
{
ys=s%2;
s=s/2;
if (ys==1)
{
count++;
}
}
printf("当这个数化为二进制数时,二进制1的个数为:");
printf("%d\n",count);
return 0;
}
时间: 2024-10-11 13:32:12