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

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

多组输入 

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

倒序输出

 1 #include <iostream>
 2 #define z 1005 
 3 using namespace std;
 4 int main()
 5 {
 6     int n,a[z]={};
 7     while(cin>>n)
 8     {int i=0;int k=n;
 9     while(k)
10     {
11         a[i++]=k%2;
12         k/=2;    
13     
14     }
15         while(i--)cout<<a[i];cout<<endl;
16     }
17 
18 }

猜你喜欢

转载自www.cnblogs.com/siuh/p/8910560.html