题目
Give you a number on base ten,you should output it on base two.(0 < n < 1000)
输入
For each case there is a postive number n on base ten, end of file.
输出
For each case output a number on base two
思路
辗转相除法做的 比较容易
代码
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
while(cin>>n)
{
int pos = 0;
int bit[11] = {0};
while(n)
{
bit[pos] = n%2;
n/=2;
pos++;
}
for(int i=pos-1;i>=0;i--)
cout<<bit[i];
cout<<endl;
}
return 0;
}