1 #include<stdio.h> 2 int main() 3 { 4 int i,n,j[31],s,a,b; 5 for(;scanf("%d",&n)==1;) 6 { 7 i=0; 8 if (n==0) 9 { 10 printf("%11d-->0\n",n); 11 continue; 12 } 13 if (n>0) 14 printf("%11d-->",n); 15 else if (n==-2147483648) 16 { 17 printf("%11d-->-10000000000000000000000000000000\n",n); 18 continue; 19 } 20 else 21 { 22 printf("%11d-->-",n); 23 n=-n; 24 } 25 for (;n!=0;i++) 26 { 27 j[i]=n%2; 28 n=n/2; 29 } 30 for (;i>0;i--) 31 { 32 printf("%d",j[i-1]); 33 } 34 printf("\n"); 35 } 36 37 38 return 0; 39 }
1015 十进制转换为二进制
时间: 2024-09-29 04:33:56