解题思路:
位运算...
注意事项:
参考代码:
#include <iostream> #include <stdio.h> #include <memory.h> #include <string> #include <math.h> #include <vector> #include <algorithm> using namespace std; string decToBin(int n) { string ans; while (n) { ans += '0' + (int)(n&1); n >>= 1; } reverse(ans.begin(), ans.end()); return ans; } int main(void) { int n; while (cin >> n) { if (n > 0) cout << n << "-->" << decToBin(n) << "\n"; else if (n < 0) cout << n << "-->" << "-" << decToBin(-n) << "\n"; else cout << "0-->0" << "\n"; } return 0; }
0.0分
1 人评分
2003年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:629 |
C二级辅导-统计字符 (C语言代码)浏览:503 |
C语言程序设计教程(第三版)课后习题7.3 (C语言代码)浏览:619 |
C语言程序设计教程(第三版)课后习题6.3 (C语言代码)浏览:510 |
简单的a+b (C语言代码)浏览:524 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:326 |
1642题解浏览:712 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:697 |
大神老白 (C语言代码)浏览:600 |
C语言程序设计教程(第三版)课后习题6.3 (C语言代码)浏览:467 |