#include <stdio.h> int main(void) { int num; int count = 0; #pragma warning(suppress : 4996)//用VS写的,需要压制警告 scanf("%d", &num); int length = sizeof(int) * 8; for (int i = 0; i < length - 1; i++) { if (num & 1) count++; num >>= 1; } printf("%d\r\n", count); return 0; }