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
#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,导致数组开小= =