Advertisement
jw910731

十進位轉二進位

Jan 2nd, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.37 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int main(int argc, const char * argv[]) {
  6.     long long int num,record=0;
  7.     scanf("%lld",&num);
  8.     while(num>0){
  9.         record += pow(10.0,(double)(long long int)log2((double)num));
  10.         num=num-pow(2.0,(double)(long long int)log2((double)num));
  11.     }
  12.     printf("%lld\n",record);
  13.     return 0;
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement