You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
|
|
int main() {
|
|
int n, i;
|
|
cin >> n;
|
|
int a[100] = {0};
|
|
for (i = 0;; ++i) {
|
|
//需要注意下面两句话的位置关系
|
|
a[i] = n % 2;
|
|
if (n / 2 > 0) {
|
|
n /= 2;
|
|
} else {
|
|
break;
|
|
}
|
|
}
|
|
//倒序输出
|
|
for (; i >= 0; i--) {
|
|
cout << a[i];
|
|
}
|
|
return 0;
|
|
}
|