模拟计算某个数的二进制,除k取余,如果等于1则统计加1

#include <stdio.h>

int fun(int n)
{
    int count = 0;
    while(n)
    {
        if(n % 2 == 1)
            count++;
        n = n>>1;
    }
    return count;
}

int main()
{
    int n;
    while(scanf("%d",&n) != EOF)
    {
        printf("%d\n",fun(n));
    }
    return 0;
}