题目如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | //Powered by TCreopargh #include<stdio.h> int main(int argc, char *argv[]) { char binRev[32],bin[32]; int dec,i=0,j; scanf("%d",&dec); if(!dec) { puts("0"); return 0; } while(dec>1) { binRev[i]=dec%2+'0'; dec/=2; i++; } if(dec) binRev[i]='1',i++; for(j=i;j>=0;j--) bin[i-j]=binRev[j-1]; puts(bin); return 0; } |
发表回复