Hdu 2051解题报告

来源:互联网 发布:绘图软件下载中文版 编辑:程序博客网 时间:2024/06/14 06:42

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


#include<iostream>using namespace std;char a[100];int Bin(int n){     int j = 1;     while(n>=2)     {        a[j++] = n%2+'0';        n = n/2;     }     a[j] = n+'0';          return j;}int main(void){    int n;        while(~scanf("%d",&n))    {         int count = Bin(n);         for(int i=count;i>0;--i)             printf("%c",a[i]);         printf("\n");    }        return 0;}


0 0
原创粉丝点击