Bitset

Problem Description
Give you a number on base ten,you should output it on base two.(0 < n < 1000)
 
Input
For each case there is a postive number n on base ten, end of file.
 
Output
For each case output a number on base two.
 
Sample Input
1
2
3
 
Sample Output
1
10
11
 
 1 #include <stdio.h> 
 2  
 3 int main(){
 4     int number;
 5     char result[20];
 6     int length;
 7     int i;
 8     
 9     while((scanf("%d",&number))!=EOF){
10         i=0;
11         while(number){
12             result[i]=number%2+'0';
13             i++;
14             number/=2;
15         }
16         length=i;
17         
18         for(i=length-1;i>=0;i--)
19             printf("%c",result[i]);
20             
21         printf("\n");
22     }
23         
24     return 0;
25 }

 

 

posted @ 2014-10-28 22:33  zqxLonely  阅读(378)  评论(0编辑  收藏  举报