1 题目编号:1015
2 题目内容:
Problem Description
Give you a number on base ten,you should output it on base two.(0 < n < 1000)
Input
For each case there is a postive number n on base ten, end of file.
Output
For each case output a number on base two.
Sample Input
1 2 3
Sample Output
1 10 11
4 解题思路形成过程:十进制转化为二进制
5 代码:
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int a[15];
int n;
while(scanf("%d",&n)!=EOF)
{
int k=0,i=0,m=0;
do{
a[i]=n%2;
n=n/2;
i++;
}
while(n!=0);
for(int j=i-1;j>=0;j--)
cout<<a[j];
cout<<endl;
}
return 0;
}