求一个整数转换为二进制数后1的个数

#include <stdio.h>
int main()
{
    printf("Enter an integer: ");
    int integer;
    scanf("%d", &integer);
    unsigned count = 0;
    do
    {
        if (integer % 2)
            ++count;
    } while (integer /= 2);
    printf("Total of 1 is %u.
", count);
    return 0;
}
原文地址:https://www.cnblogs.com/buyishi/p/8481311.html