题解 | #求int型正整数在内存中存储时1的个数#
求int型正整数在内存中存储时1的个数
https://www.nowcoder.com/practice/440f16e490a0404786865e99c6ad91c9
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> int main() { int num; int count = 0; scanf( "%d", &num); while (num) { int tmp = num % 2; num /= 2; if (tmp == 1) { count++; } } printf("%d", count); return 0; }