100.1的个数
描述小南剛學(xué)了二進(jìn)制,他想知道一個數(shù)的二進(jìn)制表示中有多少個1,你能幫他寫一個程序來完成這個任務(wù)嗎? 輸入第一行輸入一個整數(shù)N,表示測試數(shù)據(jù)的組數(shù)(1<N<1000)
每組測試數(shù)據(jù)只有一行,是一個整數(shù)M(0=<M<=10000) 輸出每組測試輸出占一行,輸出M的二進(jìn)制表示中1的個數(shù) 樣例輸入 3
4
6
7 樣例輸出 1
2
3 1 #include<stdio.h>
2 int main( ) {
3 int n, m, s;
4 scanf("%d", &n);
5 while(n--) {
6 scanf("%d", &m);
7 s=0;
8 while(m)
9 m&=m-1,s++;
10 printf("%d\n", s);
11 }
12 return 0;
13 } View Code
每組測試數(shù)據(jù)只有一行,是一個整數(shù)M(0=<M<=10000)
?
轉(zhuǎn)載于:https://www.cnblogs.com/tong69/p/5788251.html
總結(jié)
- 上一篇: elasticsearch导入数据的几种
- 下一篇: imx6 uboot lvds cloc