#include<stdio.h>
int func(int a)
{
int count = 0,i = 0;
while(a)
{
if(a&1)
{
count ++;
}
a = a>>1;
i++;
}
return (i - count);
}
int main()
{
int a = 1;
int b;
b = func(a);
printf("%d",b);
}
想到一个怎样求一个数的二进制的问题:
#include<stdio.h>
int main()
{
int n ,i = 0;
int a[100];
scanf("%d",&n);
while(n)
{
a[i] = n % 2;
n /= 2;
i++;
}
for(i= i -1;i>=0;i--)
{
printf("%d",a[i]);
}
}