题目:
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
思路: 这是10进制转2进制问题!多了不说了
#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;
// memset(a,0,sizeof(a));
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;
}
感悟:注意细节啊 因为while中的条件 我提交好几次失败!!