#include
int main()
{
int i,j,n,a[20];
while(scanf("%d",&n))
{
i = 0;
while(n>0)
{
a[i++] = n&1;
n = n>>1;
}
while(i--)
{
printf("%d",a[i]);
}
printf("\n");
}
return 0;
}
如果不需要循环输入,可以把while(scanf())改成scanf().
#include
int main()
{
int i,j,n,a[20];
while(scanf("%d",&n))
{
i = 0;
while(n>0)
{
a[i++] = n&1;
n = n>>1;
}
while(i--)
{
printf("%d",a[i]);
}
printf("\n");
}
return 0;
}
如果不需要循环输入,可以把while(scanf())改成scanf().