hdu 2051 Bitset(十进制到二进制)

Give you a number on base ten,you should output it on base two.(0 < n < 1000) 

多组输入 

利用数组  先对2取模放入数组 再将原数除以2

倒序输出


#include <iostream>
#define z 1005
using namespace std;
int main()
{
int n,a[z]={};
while(cin>>n)
{int i=0;
while(n)
{
a[i++]=n%2;
n/=2;

}
while(i--)cout<<a[i];cout<<endl;
}


}


 

posted on 2018-04-22 23:08  21我的天啊12  阅读(164)  评论(0编辑  收藏  举报