2051——Bitset

来源:互联网 发布:java模块化框架 编辑:程序博客网 时间:2024/05/22 12:28
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
123
 

Sample Output
11011
 

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

第一次老眼昏花看成n<100,导致数组开小= =
0 0