匿名用户
20级
2010-12-31 回答
#include
int main()
{ int m, a[17], i, k, p, q;
while(scanf("%d", &q) == 1)
{
if(q < 0)
m = - q;
else
{
m = q;
}
for(i = 0; i <= 16; i ++)
{
a[i] = 0;
}
p = q;
for(i = 0; (int)m != (int)0; i ++)
{
a[i] = m % 2;
m = (int)(m / 2);
}
printf("%11d-->", p);
if(p < 0)
{
printf("-");
}
for(i = 16; i >= 0; i --)
{
if(a[i] != 0)
k = 1;
if(k == 1)
{
printf("%d", a[i]);
}
}
if(q == 0)
{
printf("0");
}
k = 0;
printf("\n");
}
return 0;
}
10转2