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;
}