c语言中统计整数类数据类型二进制表示时一共包含1的个数
001、
#include <stdio.h> int main(void) { unsigned int x; printf("x = "); scanf("%u", &x); // 输出整数类数据 int count = 0; while(x) { if(x & 1U) // 判断x二进制表示时末尾是否为1; { count++; } x >>= 1; // while循环条件更新,循环一次,右移一位 } printf("count = %d\n", count); return 0; }