HDoj 2051 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
 

 

Author
8600 && xhd
 

 

Source
 

 

 

 

Recommend
linle   |   We have carefully selected several similar problems for you:  2055 2052 2053 2054 2071 
 
 
 
 
C语言代码如下:
#include<stdio.h>
int main()
{
    int n=0;
    int l=0;
    char s[20];
    while(scanf("%d",&n)!=EOF)
    {
        l=0;
        while(n!=0)
        {
            s[l++]=n%2;
            n/=2;
        }
        for(int i=l-1;i>=0;i--)
            printf("%d",s[i]);
        printf("\n");
    }
}

 

 
posted on 2020-04-09 23:20  沈香茶  阅读(92)  评论(0)    收藏  举报