nyist 100 1的個數

來源:互聯網
上載者:User

標籤:io   資料   div   時間   amp   table   程式   測試   

1的個數時間限制:3000 ms  |  記憶體限制:65535 KB難度:1 
描述
小南剛學了二進位,他想知道一個數的二進位表示中有多少個1,你能幫他寫一個程式來完成這個任務嗎?
 
輸入
第一行輸入一個整數N,表示測試資料的組數(1<N<1000)
每組測試資料只有一行,是一個整數M(0=<M<=10000)
輸出
每組測試輸出佔一行,輸出M的二進位表示中1的個數
範例輸入
3467
範例輸出
123



#include<stdio.h>
int main()
{
int m,N,count ;
scanf("%d",&N);
while(N--)
{

        count=0;
     scanf("%d",&m);


while(m!=0)
{

if(m%2==1) count++;
m=m/2;

}


printf("%d\n",count);

}
return 0;

}










聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.