码迷,mamicode.com
首页 > 其他好文 > 详细

Bitset

时间:2014-10-28 23:49:48      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   io   color   os   ar   for   sp   

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 }

 

 

Bitset

标签:des   style   blog   io   color   os   ar   for   sp   

原文地址:http://www.cnblogs.com/zqxLonely/p/4058173.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!