题解 | #查找输入整数二进制中1的个数#
查找输入整数二进制中1的个数
http://www.nowcoder.com/practice/1b46eb4cf3fa49b9965ac3c2c1caf5ad
#include<stdio.h> int main() { void cop(int a); int a[10]; for(int i=0;i<10;i++) { while(scanf("%d",&a[i])!=EOF) { cop(a[i]); } } return 0; } void cop(int a) { int b,sum=0; while(a!=0) { b=a%2; a=a/2; if(b==1) sum++; } printf("%d\n",sum); }
