PS:题干中说明注意多组输入。写的时候要注意一下,不能只取一个数。
#include<stdio.h> int main(){ int a=0, sum=0; while(scanf("%d", &a) != EOF){ sum = 0; while(a){ sum += a%2; a /= 2; } printf("%d\n", sum); } return 0; }
#include<stdio.h> int main(){ int a=0, sum=0; while(scanf("%d", &a) != EOF){ sum = 0; while(a){ sum += a%2; a /= 2; } printf("%d\n", sum); } return 0; }