需求:求一个整数存储在内存中二进制中的1的数量
#define _CRT_SECURE_NO_WARNINGS 1 #include <stdio.h> int main() { int num = 0; int input = 0; printf("请输入你想要统计的数字:"); scanf("%d", &input); int i = 0; for (i = 0; i < 32; i++) { if (1 == ((input >> i) & 1)) { num++; } } printf("1的数量是:%d", num); return 0; }
标签:26,int,代码,练习,++,num,printf,input From: https://www.cnblogs.com/ayue6/p/17748612.html