专题三 第七题

1.题目编号:1015

2.简单题意:给出一个十进制数输出它的二进制数。

3.解题思路形成过程:在现实生活中我们求十进制转化成二进制只需要将这个数短除2直至商为0,从下到上取余数。按照这个思想就可以了~

4.感悟:不知道为什么将存余数的p数组改成int类型就不好使呢?

5.AC的编码:

#include<iostream>
using namespace std;
int main()
{
    int n,r;
    int i=0;
    char p[15];
   while(cin>>n){
       r=1;
          while(r){
              i++;
              r=n/2;
        p[i]=n%2+'0';
        n/=2;
    }
   for(;i>0;i--){
   cout<<p[i];
   }
   cout<<endl;
    }
    return 0;
}

原题:

Problem Description


Give you a number on base ten,you should output it on base two.(0 &lt; n &lt; 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


你可能感兴趣的:(专题三 第七题)