1.5 [hduoj] 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

扫描二维码关注公众号,回复: 8851233 查看本文章

1

10

11

#include<stdio.h>
void main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        int i=0;
        int a[10];
        while(n!=1&&n!=0)
        {
            a[i]=n%2;
            n=n/2;
            i++;
        }
        if(n==0)
            printf("%d",0);
        else
        {
            printf("%d",1);
            if(i!=0)
            {
                while(i--)
                    printf("%d",a[i]);
            }
        }
        printf("\n");
    }
}

嗷。就是二进制转换。

发布了153 篇原创文章 · 获赞 4 · 访问量 3721

猜你喜欢

转载自blog.csdn.net/qq_39782006/article/details/103843762
1.5