[恢]hdu 2051

2011-12-15 00:03:00

地址:http://acm.hdu.edu.cn/showproblem.php?pid=2051

题意:输入十进制n,输出n的二进制。

mark:注意n=0的情况。

代码:

# include <stdio.h>


void output(int n)
{
if (n == 0) return ;
output (n>>1) ;
putchar ((n&1) + '0') ;
}


int main ()
{
int n ;
while (~scanf ("%d", &n))
{
if (n == 0) puts ("0") ;
else{
output(n) ;
puts ("") ;
}
}
return 0 ;

}



原文地址:https://www.cnblogs.com/lzsz1212/p/2314592.html