Advertisement
lily09290110

二進制轉化

Jan 12th, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.32 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4.    int a,temp,i;
  5.    char b[100];
  6.    while(scanf("%d",&a)==1)
  7.    {
  8.      i=0;
  9.      temp=a;
  10.      do
  11.      {
  12.       b[i]=48+temp%2;
  13.       i++;
  14.      }while((temp/=2)!=0);
  15.      while(i>=0)
  16.      {
  17.          i--;
  18.          printf("%c",b[i]);
  19.      }
  20.      printf("\n");
  21.    }
  22.   return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement