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
題意:給出一個十進制數 n,将其轉為二進制後輸出
Source Program
#include<iostream>
using namespace std;
int main()
{
int n;
int a[100];
int i,j;
while(cin>>n)
{
i=0;//位數計數清零
while(n)//進制轉換,每一位放在a[i]中
{
a[i]=n%2;
n=n/2;
i++;
}
for(j=i-1;j>=0;j--)//從低位取出,逆序輸出
cout<<a[j];
cout<<endl;
}
return 0;
}