自己写的。C语言。题解 | #查找输入整数二进制中1的个数#
查找输入整数二进制中1的个数
https://www.nowcoder.com/practice/1b46eb4cf3fa49b9965ac3c2c1caf5ad
#include<stdio.h> int main() { int nums[1000]; int i = 0, n, sum; while (scanf("%d", &nums[i]) > 0) { i++; } n = i; for (i = 0; i < n; i++) { sum = 0; while (nums[i] > 0) { if (nums[i] % 2 == 1) { sum++; } nums[i] /= 2; } printf("%d\n", sum); } return 0; }