训练3 习题15

来源:互联网 发布:秋冬防晒 知乎 编辑:程序博客网 时间:2024/05/21 11:36
题目: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
123
 

Sample Output
11011
 


思路:   这是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中的条件  我提交好几次失败!!


0 0
原创粉丝点击