Description
给定一个十进制整数N,求其对应2进制数中1的个数
Input
第一个整数表示有N组测试数据,其后N行是对应的测试数据,每行为一个整数。
Output
N行,每行输出对应一个输入。
Sample Input
4 2 100 1000 66
Sample Output
1 3 6 2
#include <stdio.h>
int main()
{
int t, n;
int cnt;
scanf("%d", &t);
while (t--){
scanf("%d", &n);
cnt = 0;
while (n){
if (n % 2 == 1)
cnt++;
n /= 2;
}
printf("%d\n", cnt);
}
return 0;
}