hdu 2051 Bitset (decimal to binary)

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

Multiple input 

Use the array to first take the modulo 2 and put it into the array and then divide the original number by 2

output in reverse order

 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 }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324764495&siteId=291194637