Y

来源:互联网 发布:淘宝买啥弓箭好 编辑:程序博客网 时间:2024/06/08 11:30

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

#include<stdio.h>#define maxn 100000int main(){    int x;    int a[maxn];    int count,i,n;    while(scanf("%d",&x)==1)    {    for(i=0; ; i++)    {        n=0;        n=x % 2;        a[i] = n;        x = (x-n)/2;        count = i;        if (x<1)        break;    }    for(i=count; i>=0; i--)        printf("%d",a[i]);    printf("\n");    }    return 0;   }
原创粉丝点击