當前位置:編程學習大全網 - 網站源碼 - 急求c語言程序輸入壹個整數(int),要求輸出其二進制形式的值。

急求c語言程序輸入壹個整數(int),要求輸出其二進制形式的值。

我也發壹個自編的,已驗證通過。

#include <stdio.h>

main()

{

char binOut[17];

short int i, j; /* 16bit的整數,要用short int型 */

scanf("%d", &i);

for(j=15;j>=0;j--)

{

if(i&(1<<j))

binOut[15-j] = '1';

else

binOut[15-j] = '0';

}

binOut[16] = 0;

printf("DEC(%d)=BIN(%s)\n",i,binOut);

}

  • 上一篇:自動發貨qq臨時小號 怎麽註冊的
  • 下一篇:精準的動物指標是什麽意思
  • copyright 2024編程學習大全網